我可以向$ to字段发送电子邮件,但我必须向用户发送电子邮件,同时他已收到他的提交。 我必须发送电子邮件到$ _POST [“email”]
这是代码
<?php
$ToEmail = 'abc@gmail.com,def@gmail.com';
$EmailSubject = 'Successfull Contact Form Submission';
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["fname"]."\r\n";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."\r\n";
$MESSAGE_BODY .= "Company: ".$_POST["company"]."\r\n";
$MESSAGE_BODY .= "Address: ".$_POST["address"]."\r\n";
$MESSAGE_BODY .= "City: ".$_POST["city"]."\r\n";
$MESSAGE_BODY .= "State: ".$_POST["state"]."\r\n";
$MESSAGE_BODY .= "Zip: ".$_POST["zip"]."\r\n";
$MESSAGE_BODY .= "Phone: ".$_POST["phone"]."\r\n";
$MESSAGE_BODY .= "Fax: ".$_POST["fax"]."\r\n";
$MESSAGE_BODY .= "Comment: ".nl2br($_POST["message"])."\r\n";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
?>
答案 0 :(得分:0)
你可以使用抄送头甚至是密送:
$mailheader = "Cc: ".$_POST["email"]."\r\n";
或
$mailheader = "Bcc: ".$_POST["email"]."\r\n";
答案 1 :(得分:0)
$toEmails[] = 'abc@gmail.com,def@gmail.com'; $toEmails[] = $_POST['email']; (...) foreach ($toEmails as $email) { mail($email, $EmailSubject, $MESSAGE_BODY, $mailheader) or die('Failure'); }
但错误的方法是死错()。更好地捕获异常错误并使用正确的电子邮件继续运行脚本。