我对此进行了深入研究。在这里,在 Stack Overflow,我发现如果想要退回无法投递的邮件,需要在 php mail() 函数中使用 -f 参数。以下是我的脚本(就目前而言):
//Send Confirmation email. Following are the variables for the email
// mail function best practices: http://collaborate.extension.org/wiki/Best_Practices_Using_the_PHP_mail_Function
$sendto = $email; // this is the email address collected from the foreach routine.
$e_subject = stripslashes($subject); // Subject
//$message = "<html>" . stripslashes($body) . "</html>";
$message = "
<html>
<body>
<p>Hello " . stripslashes($fName) . ":</p>
<div>" . stripslashes($body) . "</div>
</body>
</html>
";
// Always set content-type when sending HTML email
$header = "MIME-Version: 1.0" . "\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";;
// extract user domain so you can set up X-Mailer
$u_domain=substr(strrchr($user_email, '@'), 1);
$dom_array = explode(".",$u_domain);
$user_domain = $dom_array[0];
$header .= "X-Mailer: ". $user_domain ."\r\n";
$header .= "X-Sender-IP: {$_SERVER['REMOTE_ADDR']}\r\n";
$header .= "X-Originating-IP: [".getenv("REMOTE_ADDR")."]\r\n";
$header .= "From: " . $user_email . "\r\n";
$header .= "Sender: ". $user_email . "\r\n";
// The "envelope sender" is the address listed in the "Return-Path:" header - and controls where the email is sent to in the event that a recipient address bounces. http://collaborate.extension.org/wiki/Best_Practices_Using_the_PHP_mail_Function
$header .= "Return-Path:" . $user_email . "\r\n";
$header .= "Reply-To:" . $user_email . "\r\n";
$bounceTo = "-f". $user_email;
// Collect variables from above and insert into the mail() function.
mail($sendto, $e_subject, $message, $header,$bounceTo);
你会注意到很多评论——我只是想弄清楚这一点。我的 mail() 发送非常好。邮件以应有的格式进入我的收件箱。但是... $bounceTo 变量 ("-f" . $user_email) 不起作用。我故意邮寄到 3 个已知的非活动地址,但我没有收到任何退回邮件。
上述代码中的所有标题设置都已到位,因为我了解到这些可能会影响反弹。我完全愿意摆脱不必要的标题并添加必要的内容。但是......在这一点上,脚本似乎一团糟——没有产生反弹。
欢迎任何建议。
非常感谢:
亭