2012-07-05 46 views
0

我已經對此進行了強烈的研究。在這裏,在堆棧溢出中,我發現如果有人想讓無法投遞的郵件反彈回來,那麼需要在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個已知的非活動地址,我沒有得到任何反彈。

上述代碼中的所有標題設置都已存在,因爲我瞭解到這些可能會影響反彈。我完全願意擺脫不必要的標題並添加必要的內容。但是......在這一點上,腳本似乎是一團糟 - 這不會產生反彈。

歡迎任何建議。

感謝很多:

回答

0

你有沒有看着張貼在http://www.php.net/manual/en/function.mail.php#107321評論。這可能會使你朝着正確的方向前進。

+0

http://www.php.net/manual/en/function.mail.php#94170上的這一項也可能對您有所幫助。 – jg314 2012-07-05 22:13:19

+0

是的 - 我在發佈之前先查看了該帖子。所有反彈應採用與From相同的返回路徑,因此該帖子中的建議不適用。 – Pavilion 2012-07-05 23:55:58

0

This thread explaining bounced mail in php可能對您有益。我個人從未必須使用-f參數來處理退回的電子郵件。

+0

是的 - 我已經查看過這個線程 - 它確實和我的應用程序不一樣。反彈電子郵件地址將隨每個用戶而改變。 – Pavilion 2012-07-05 23:59:29

0

在所有服務器上都不允許使用-f覆蓋退回地址,尤其是在共享託管服務器上時,這通常是不可能的。在這種情況下,最好不要使用非常有限的mail()函數,而應使用像phpmailerswiftmailer這樣的smtp庫。

順便說一句:你不必發送郵件到非活動地址來檢查你的退回地址。將它們發送到活動帳戶,在消息源中查找「Return-Path」標題,這是反彈地址。

+0

好的 - 我只是嘗試phpmailer,它導致更多的問題比它解決: – Pavilion 2012-07-06 15:03:25

+0

好吧 - 我只是嘗試phpmailer,它會導致更多的問題,而不是它解決: 1.仍然沒有得到反彈電子郵件回。 2.使用變量將用戶輸入的內容傳遞給正文,正文不拾取用戶輸入的內容。 3.身體正在拿起第一個標準段落,但它不通過html。人們可以看到html標籤,就好像它們是文本本身的一部分。 4.以前,郵件()函數只向收件人的姓名發送電子郵件地址給每個收件人。現在(使用phpmailer)TO包含所有收件人的名稱 - 這不是一件好事。 – Pavilion 2012-07-06 15:11:45