I’ve searched and searched for something similar, but i think i’m not doing it right. So i will ask a question. This is very basic. My problem is as follows:
I have a multi-page form, consisting of 4 pages + 1 preview page. On the preview page, upon submitting i want the entire form data to be sent to 2 different mail adresses. One standard, and the other one, the one that the user has submitted.
So i have:
<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
?>
<?php
$email_from = 'mail@company.com';
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n".
"Here is the message:\n $message".
$to = "yourname@yourwebsite.com, $email /n";
$headers = "From: Company";
mail($to,$email_subject,$email_body,$headers);
?>
How should I insert the submitted $email variable in order for it to work?
According to the
mail()function documentation the$toparameter will take a comma-separated list of addresses as you have attempted, but should have no line break at the end.Also, your variable is
$visitor_email, rather than$email.You might also consider adding the visitor’s email as a CC or BCC rather than the TO address. In that case, add it as a CC or BCC header (separated by
\r\n), but you need to be cautious to be sure that the address is an email address and contains no line break characters which could be used for header injection.