【问题标题】:PHP mail() -f parameter is NOT workingPHP mail() -f 参数不起作用
【发布时间】:2012-07-06 09:10:35
【问题描述】:

我对此进行了深入研究。在这里,在 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 个已知的非活动地址,但没有收到任何退回邮件。

以上代码中的所有标题设置都已到位,因为我了解到这些可能会影响反弹。我完全愿意摆脱不必要的标题并添加必要的内容。但是...在这一点上,脚本似乎一团糟——没有产生反弹。

欢迎提出任何建议。

非常感谢:

展馆

【问题讨论】:

    标签: php email


    【解决方案1】:

    您是否看过http://www.php.net/manual/en/function.mail.php#107321 上发布的评论。这可能会引导您朝着正确的方向前进。

    【讨论】:

    • php.net/manual/en/function.mail.php#94170 的那个也可能对你有帮助。
    • 是的 - 我在发帖之前查看了该帖子。所有退回邮件都应采用与 From 相同的返回路径,因此该帖子中的建议不适用。
    【解决方案2】:

    This thread explaining bounced mail in php 可能对您有帮助。我个人从未使用过-f 参数来处理退回的电子邮件。

    【讨论】:

    • 是的 - 我已经查看了该线程 - 它确实与我的应用程序不同。退回的电子邮件地址会随每个用户而改变。
    【解决方案3】:

    不允许在所有服务器上使用 -f 覆盖退回地址,尤其是在共享托管服务器上时,这通常是不可能的。在这种情况下,通常最好不要使用非常有限的 mail() 函数,而是使用像 phpmailerswiftmailer 这样的 smtp 库。

    顺便说一句:您不必向非活动地址发送邮件来检查您的退回地址。将它们发送到活动帐户,在消息源中查找“Return-Path”标头,这是退回地址。

    【讨论】:

    • 好的 - 我刚刚尝试了 phpmailer,它导致的问题比它解决的问题多:
    • OK - 我刚刚尝试了 phpmailer,但它导致的问题多于解决的问题: 1. 仍然没有收到退回的电子邮件。 2. 使用变量将用户输入的内容传递给正文,正文不会获取用户输入的内容。 3. 正文选择了第一个标准段落,但它不是作为 html 进行的。人们可以看到 html 标签,就好像它们是文本本身的一部分一样。 4. 以前,mail() 函数向每个收件人发送一个电子邮件地址,在 TO: 中只有该收件人的姓名。现在(使用 phpmailer)TO 包含所有收件人的姓名 - 这不是一件好事。
    猜你喜欢
    • 2014-03-17
    • 1970-01-01
    • 1970-01-01
    • 2015-02-01
    • 2011-08-15
    • 2011-09-18
    • 1970-01-01
    • 2015-04-16
    相关资源
    最近更新 更多