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('', 'Reply to name');
$mail->AddAddress('', 'User name);
$mail->SetFrom('', '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: