使用PHPMailer更改返回路径

Rol*_*and 9 php phpmailer

有没有办法使用PHPMailer更改返回路径

我做了以下,但没有奏效

$mail->AddCustomHeader('Return-path:test@email.co.za');
Run Code Online (Sandbox Code Playgroud)

我正在使用以下语句发送邮件

if(!$mail->Send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;

    } else {
        //Building the reporting email to report on all the mails send 
        echo "Message REPORT sent!\n";
    }
Run Code Online (Sandbox Code Playgroud)

我收到了电子邮件,但返回路径没有变化?

Rol*_*and 24

以下解决了这个问题,我调整了Sender属性,它对我有用. $mail->Sender = 'test@email.co.za';


Y T*_*sky 6

设置返回路径的正确方法(截至2013年7月)是使用:

$mail->ReturnPath='bounce_here@domain.com';
Run Code Online (Sandbox Code Playgroud)

phpmailer源码包含以下内容,这就是我认为$ mail-> Sender工作的原因

if ($this->ReturnPath) {
  $result .= $this->HeaderLine('Return-Path', '<'.trim($this->ReturnPath).'>');
} elseif ($this->Sender == '') {
  $result .= $this->HeaderLine('Return-Path', '<'.trim($this->From).'>');
} else {
  $result .= $this->HeaderLine('Return-Path', '<'.trim($this->Sender).'>');
}
Run Code Online (Sandbox Code Playgroud)

  • 这应该被标记为正确答案。 (2认同)
  • 这已不再是这种情况,因为phpmailer在其代码中显示:/***消息的返回路径.*如果为空,则将其设置为From或Sender.*var string*deprecated电子邮件发件人不应该设置返回路径头;*这是接收者的工作(RFC5321第4.4节),所以这不再做任何事情.*链接https://tools.ietf.org/html/rfc5321#section-4.4 RFC5321参考*/ (2认同)