开发者

Changing the Return-path using PHPMailer

Is there a way to change the return-path using PHPMailer

I did the following and it did not work

$mail->AddCustomHeader('Return-path:test@email.co.za');

I'm using the following statement to send mails

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

    } else {
        //Building the reporting email to re开发者_开发技巧port on all the mails send 
        echo "Message REPORT sent!\n";
    }

I get the email but the return path does not change?


The following solved the issue, I adjusted the Sender property and it worked for me. $mail->Sender = 'test@email.co.za';


the correct way to set returnpath (as of july 2013) is by using:

$mail->ReturnPath='bounce_here@domain.com';

the phpmailer source contains the following, which is why I think $mail->Sender worked

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


$mail->Sender = 'noreply@domain.com';


The most probable reason for this is that the mail server you’re sending this mail over enforces a specific return path. This is often the case for “hosted” webspace.

In that case, you don’t have a lot of options. Try talking to your hoster.


Instead of using the Reply-path header, try this:

$mail->AddCustomHeader('Reply-to:test@email.co.za');

I use the Reply-to header and have had great success even on shared spaces.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜