Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPMailer bounced mails not getting bounced right

I have written a PHP script, which sends mails. I'm sending them from "[email protected]" and have also set the "Return-Path" to "[email protected]", but I'm still getting bounced mails to senders mail ("[email protected]").

Here is stripped down code:

$this->mail = new PHPMailer();
$this->mail->isSMTP();
$this->mail->Host = 'host';
$this->mail->SMTPAuth = true;
$this->mail->Username = '[email protected]';
$this->mail->Password = 'pass';
$this->mail->SMTPSecure = 'tls';
$this->mail->Port = 25;
$this->mail->ReturnPath = '[email protected]';
$this->mail->From = '[email protected]';
$this->mail->send();

How could I force the bounced mails to go to the bounce mail account? Thanks for any help!

like image 698
n00b Avatar asked Jan 28 '26 16:01

n00b


1 Answers

Don't use ReturnPath - set Sender instead. Support for the ReturnPath property was recently disabled in PHPMailer (in version 5.2.8) because it's invalid to set it at the point of sending. The return path is added by the receiver when it receives the message, and is set by putting your desired return path into the Sender property, which gets passed as the envelope sender during the SMTP conversation. Sender is set automatically when you call setFrom, but you can override it and just set it directly, like this:

$this->mail = new PHPMailer();
$this->mail->isSMTP();
$this->mail->Host = 'host';
$this->mail->SMTPAuth = true;
$this->mail->Username = '[email protected]';
$this->mail->Password = 'pass';
$this->mail->SMTPSecure = 'tls';
$this->mail->Port = 25;
$this->mail->setFrom('[email protected]');
$this->mail->Sender = '[email protected]';
$this->mail->send();
like image 127
Synchro Avatar answered Jan 31 '26 06:01

Synchro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!