PHPMailer: AddReplyTo not working/being ignored Tips, Tricks and Tutorials 15 JUL 2015

PHPMailer is a popular full-featured email creation and transfer class for PHP, and one that I most often use in my projects.

We recently spotted an issue whereby we were setting the AddReplyTo field to a mail object for send out, but on subsequent send, the mail clients seemed to all be ignoring what we had set as the e-mail address which “Reply To” should use! Essentially it was as if AddReplyTo is either not working or being ignored – more than just a little annoying indeed!

It turns out however that there was (or perhaps still is) an issue whereby if an e-mail address is set via the SetFrom call before you set the AddReplyTo call, the Reply To address is simply ignored when the e-mail headers are constructed. So a simple fix is to call AddReplyTo first, before calling SetFrom.

So in other words, the correct order should be:

$mail->AddReplyTo('replyto@email.com', 'Reply to name');
$mail->AddAddress('user@email.com', 'User name);
$mail->SetFrom('mailbox@email.com', 'Mailbox name');

This behaviour may have subsequently changed in newer versions of the PHPMailer class, but if you’re having the same issue that I was having, this is most definitely a quick and easy fix!

postman pat with boombox

Related Link: https://github.com/Synchro/PHPMailer

Related Posts:

About Craig Lotter

Software developer, husband and dad to two little girls. Writer behind An Exploring South African. I don't have time for myself any more.