PHP mail()-f参数不起作用 [英] PHP mail() -f parameter is NOT working

查看:78
本文介绍了PHP mail()-f参数不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对此进行了深入研究。在这里,我在Stack Overflow上发现,如果要使无法传递的邮件反弹,则需要在php mail()函数中使用-f参数。以下是我的脚本(目前为止):

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

您会注意到很多评论-我只是想弄清楚这一点。我的mail()发送得很好。邮件以应有的格式进入我的收件箱。但是... $ bounceTo变量( -f。$ user_email)无法正常工作。我有意邮寄到3个已知的非活动地址,并且没有收到任何退信。

You'll notice a lot of commenting - I'm just trying to figure this out. My mail() sends wonderfully. The mail is coming into my inbox with formatting as it should be. But... the $bounceTo variable ("-f" . $user_email) is not working. I've intentionally mailed to 3 known inactive addresses, and I'm not getting any bounce backs.

上面代码中的所有标头设置均已就绪,因为我们了解到这些可能会影响反弹。我完全愿意摆脱不必要的标题,并添加必要的内容。但是...在这一点上,脚本似乎很混乱-不会产生反弹。

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.

欢迎任何建议。

非常感谢:

展馆

推荐答案

在所有服务器上均不允许使用-f覆盖退回地址,尤其是在共享主机服务器上时,通常是不可能的。在这种情况下,通常最好不要使用非常有限的mail()函数,而要使用smtp库,例如 phpmailer swiftmailer 代替。

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. 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.

顺便说一句:将邮件发送到无效地址以检查您的退回地址。将它们发送到活动帐户,在消息源中查找 Return-Path标头,这是退信地址。

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.

这篇关于PHP mail()-f参数不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆