-2

我可以向 $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");
 ?>
4

2 回答 2

0
  1. 错误的骆驼包。您只能在课程中使用首字母驼峰式。
$toEmails[] = 'abc@gmail.com,def@gmail.com';
$toEmails[] = $_POST['email'];

(...)

foreach ($toEmails as $email) {
     mail($email, $EmailSubject, $MESSAGE_BODY, $mailheader) or die('Failure');    
}

但是 die() on error 是错误的方式。更好地将错误捕获到异常并使用正确的电子邮件继续运行脚本。

于 2013-01-17T09:07:48.883 回答
0

您可以使用 th Cc 标头甚至 Bcc:

$mailheader = "Cc: ".$_POST["email"]."\r\n";

或者

$mailheader = "Bcc: ".$_POST["email"]."\r\n";
于 2013-01-17T08:56:00.280 回答