简体   繁体   English

PHP mail()-f参数不起作用

[英]PHP mail() -f parameter is NOT working

I've researched this intensely. 我对此进行了深入研究。 Here, at Stack Overflow, I've figured out that one needs to use an -f parameter with the php mail() function, if one wants undeliverable mail to bounce back. 在这里,在Stack Overflow上,我发现如果要使无法传递的邮件反弹,则需要在PHP mail()函数中使用-f参数。 Following is my script (as it stands now): 以下是我的脚本(目前为止):

//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);

You'll notice a lot of commenting - I'm just trying to figure this out. 您会注意到很多评论-我只是想弄清楚这一点。 My mail() sends wonderfully. 我的mail()发送得很好。 The mail is coming into my inbox with formatting as it should be. 邮件以应有的格式进入我的收件箱。 But... the $bounceTo variable ("-f" . $user_email) is not working. 但是... $ bounceTo变量(“ -f”。$ user_email)不起作用。 I've intentionally mailed to 3 known inactive addresses, and I'm not getting any bounce backs. 我有意邮寄到3个已知的无效地址,但没有收到任何退信。

All the header settings in the above code are in place because I've learned that these may affect bounce backs. 上面代码中的所有标头设置均已就绪,因为我了解到它们可能会影响反弹。 I'm totally willing to get rid of un-necessary headers and add what is necessary. 我完全愿意摆脱不必要的标题,并添加必要的内容。 But... at this point the script seems to be a mess -which is not producing bounce backs. 但是...此时,脚本似乎一团糟-不会产生反弹。

Any suggestions are welcome. 欢迎任何建议。

Thanks Much: 非常感谢:

Pavilion

Have you looked at the comment posted at http://www.php.net/manual/en/function.mail.php#107321 . 您是否看过http://www.php.net/manual/en/function.mail.php#107321上发布的评论。 That might lead you in the right direction. 这可能会引导您朝正确的方向前进。

This thread explaining bounced mail in php might be of benefit to you. 该线程解释php中的退回邮件可能对您有益。 I personally have never had to use the -f parameter to handle bounced emails. 我个人从来不需要使用-f参数来处理退回的电子邮件。

Overriding the bounce address with -f is not allowed on all servers, especially if you are on a shared hosting server this is often not possible. 不允许在所有服务器上使用-f覆盖退回地址,尤其是在共享主机服务器上时,通常是不可能的。 In this case, it's often better not to use the very limited mail() function but use a smtp library like phpmailer or swiftmailer instead. 在这种情况下,通常最好不要使用非常有限的mail()函数,而应使用phpmailerswiftmailer之类的smtp库。

Btw: you don't have to send mails to an inactive address to check your bounce address. 顺便说一句:您不必将邮件发送到无效的地址即可查看您的退回地址。 Send them to an active account, in the message source look for the "Return-Path" header, this is the bounce address. 将它们发送到活动帐户,在消息源中查找“ Return-Path”标头,这是退回地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM