I am able to send emails to the $to fields but i have to send email to the user also that his submission has been received. i have to send email to $_POST["email"]
here is the code
<?php
$ToEmail = 'abc@gmail.com,def@gmail.com';
$EmailSubject = 'Successfull Contact Form Submission';
$mailheader = "From: ".$_POST["email"]."
";
$mailheader .= "Reply-To: ".$_POST["email"]."
";
$mailheader .= "Content-type: text/html; charset=iso-8859-1
";
$MESSAGE_BODY = "Name: ".$_POST["fname"]."
";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."
";
$MESSAGE_BODY .= "Company: ".$_POST["company"]."
";
$MESSAGE_BODY .= "Address: ".$_POST["address"]."
";
$MESSAGE_BODY .= "City: ".$_POST["city"]."
";
$MESSAGE_BODY .= "State: ".$_POST["state"]."
";
$MESSAGE_BODY .= "Zip: ".$_POST["zip"]."
";
$MESSAGE_BODY .= "Phone: ".$_POST["phone"]."
";
$MESSAGE_BODY .= "Fax: ".$_POST["fax"]."
";
$MESSAGE_BODY .= "Comment: ".nl2br($_POST["message"])."
";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
?>
You can use th Cc header or even Bcc:
$mailheader = "Cc: ".$_POST["email"]."
";
or
$mailheader = "Bcc: ".$_POST["email"]."
";
$toEmails[] = 'abc@gmail.com,def@gmail.com'; $toEmails[] = $_POST['email']; (...) foreach ($toEmails as $email) { mail($email, $EmailSubject, $MESSAGE_BODY, $mailheader) or die('Failure'); }
But die() on error is wrong way. Better catch error to exception and continue script running with correct emails.