+44 (791) 5698 086

PHPMailer – Tips and fixes

This post will cover various common issues encountered with PHPMailer and how to resolve them. It will also include various tips to improve its usage.

I will keep updating this post with content related to PHPMailer as it comes along.

Set different but single reply-to email address

You can provide a different reply-to address to PHPMailer, however it doesn’t get set as a single email id. It gets added along with the “from” email id, making 2 email ids in the reply-to field. If you’ve been looking for ways regarding how to set only one reply to address in PHPMailer, there’s a very easy way to do this!

The trick is to define the reply-to email before the from email.

This is because while running the main function, it checks if the reply-to address is empty then it sets it to the from address field.

if (empty($this->ReplyTo)) {
   $this->AddAnAddress('ReplyTo', $address, $name);
}

So solution is to add the replyto address before the from one, like this:

$mail->AddReplyTo($replytoemail,"Liquid Imaging");
$mail->SetFrom($fromemail, 'Liquid Imaging');

If you’re in a situation where it’s already set and nothing can be done about it, then try using the “clearreplytos” function of PHPMailer like this

$mail->ClearReplyTos();
$mail->addReplyTo([email protected].com, 'EXAMPLE');

Hope this helps. If you have any query or suggestion please let me know.

Update:

If you’re unable to find or unsure where to find this code, look for the main phpmailer class file in your installation package. We can’t give you the exact path as it depends on the package or plugin you’re using. Look for class-phpmailer.php or phpmailer.php etc. for an idea in your directory.

2 Responses to PHPMailer – Tips and fixes

  1. Marcus Bointon

    I’ve no idea what you’re talking about in this post. The code you quote does not appear anywhere in PHPMailer, and nor does it ever put a from address into a reply-to header.

    • Nabtron

      Look for class-phpmailer.php or phpmailer.php etc. for an idea in your directory.

Leave a Reply

Your email address will not be published. Required fields are marked *

Who are we?

Nabtron team includes web, desktop software and mobile apps developers along with SEO professionals.

We are available 24 hours, 7 days a week. Contact us now for anything you need!

Join our mailing list

Lets become friend :) What's your name & email?