我已經對此進行了強烈的研究。在這裏,在堆棧溢出中,我發現如果有人想讓無法投遞的郵件反彈回來,那麼需要在php mail()函數中使用-f參數。以下是我的腳本(如現在的情況):PHP郵件()-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);
你會發現有很多評論的 - 我只是想弄清楚這一點。我的郵件()發送奇妙。郵件正在進入我的收件箱,並且應該是格式化的。但是... $ bounceTo變量(「-f」。$ user_email)不起作用。我有意郵寄到3個已知的非活動地址,我沒有得到任何反彈。
上述代碼中的所有標題設置都已存在,因爲我瞭解到這些可能會影響反彈。我完全願意擺脫不必要的標題並添加必要的內容。但是......在這一點上,腳本似乎是一團糟 - 這不會產生反彈。
歡迎任何建議。
感謝很多:
館
http://www.php.net/manual/en/function.mail.php#94170上的這一項也可能對您有所幫助。 – jg314 2012-07-05 22:13:19
是的 - 我在發佈之前先查看了該帖子。所有反彈應採用與From相同的返回路徑,因此該帖子中的建議不適用。 – Pavilion 2012-07-05 23:55:58