I'm using phpmailer on my ERP and the from email is a noreply@ and the reply-to is my client/company email. Sometimes I'm receiving "Mail delivery failed: returning message to sender" that is normal but I'm receiving those to my noreply@ and not the client email. How can I force the phpmailer to send the "Mail delivery failed" to reply-to email? Thank you for your help.
Bounces go to the return-path
, not the reply-to
address, because they are bounces, not replies.
It's not PHPMailer that's sending your bounces there, it's the receiver, and they are acting correctly.
You can set the return path indirectly using the Sender
property which is used to set the envelope sender, which the receiver converts into a return-path before attempting delivery. Do not be tempted to set a return-path
header yourself; it's the receiver's job.
$mail->Sender = 'bounces_go_here@example.com';
Beware though – this address is what SPF applies to, so you need to be very sure that your SPF records are set up correctly. For reliable bounce handling, I'd recommend making use of VERP addressing here too.