Reputation: 59
I am trying to create three forms that each send emails using php. In the second and third forms the variable wont output the value assigned to it. I used the $_POST function and the $_REQUEST in the second and third form. In the first form the email was sent and all the variables are able to appear normally. The information is being stored normally in the database. The only problem is the variable is not seen in the email that is sent from the second and third from and I have no idea how to make it work. Here is an rough example of what has happened.
$x = new mysql($connection_information);
$x->update(array('email' => $_POST['email'], 'xemail' => $_POST['xemail'], 'parking' = $_POST['parking'] etc)
$email = $_POST['email'];
$xemail = $_POST['xemail'];
$subject = "Form Request " . $email;
$headers = 'From: ' . $xemail . "\r\n" .
$message = "this email will. $_POST['parking']"
mail($email, $subject, $message, $header);
There is much more to this I am just making it as simple as I can. Its the message area that is not seeing the variable, Does anyone know what is causing this problem?
Upvotes: 1
Views: 183
Reputation: 2246
You could try this instead. It's a little harder to read the text, but a lot easier to see where your variables are:
$message = "this email will. ".$_POST['parking'];
Also, this line above it is open-ended and will cause the PHP interpreter to fail:
$headers = 'From: ' . $xemail . "\r\n" .
Overall I think you want your code something like this:
$x = new mysql($connection_information);
$x->update(array('email' => $_POST['email'], 'xemail' => $_POST['xemail'], 'parking' => $_POST['parking']);
$email = $_POST['email'];
$xemail = $_POST['xemail'];
$subject = "Form Request ".$email;
$headers = "From: ".$xemail."\r\n";
$message = "this email will. ".$_POST['parking'];
mail($email, $subject, $message, $header);
Upvotes: 1
Reputation: 71384
When referencing an array key inside a double-quoted text string I find it best to use curly bracket syntax like:
$message = "this email will. {$_POST['parking']}";
The same can be said for trying to access object properties as well.
Upvotes: 1