10

After upgrading to Joomla 3.5.1, I get an Invalid Address error in some of my extensions that use PHPMailer (the Joomla Mailing system).

How can I fix this?

2 Answers 2

16

Answer for Users:

If you are getting this error because you are using some extension that sends emails, please visit the developer page, and first make sure you are using the latest version.

If you are 100% sure that you are using the latest version, but still getting this error, you should contact the developer and ask them about this error. Sending them a link to this page, may help the developer to fix this error.

If you consider yourself experienced enough with PHP, you may try to patch the code on your own, using the "answer for developers", below.

Please note that this will not be a permanent solution, but just a "patch", until the developer issues a new version.

Answer for Developers:

Joomla 3.5.1 enables PHPMailer's exceptions by default. Thus errors that were previously hidden show up.

One case where this shows now is with the addReplyTo function.

In Joomla 2.5 addReplyTo had an array parameter.

Beginning with Joomla 3.0 (yes, back in 2012) Joomla's JMail function changed to not handle arrays differently than string parameters. Thus it relied on the underlying PHPMailer code, which however changed also and thus fails to add the Reply-To correctly.

PHPMailer does throw an Exception for that, however up until Joomla 3.5.1 nobody saw that exception if you did not enable the exception handling manually!

Solution

You may search your extension code for addReplyTo and change lines like this:

 $mailer->addReplyTo(array($replyTo, $replyToName));

to this:

if(version_compare(JVERSION, '3.0', 'ge')) {
  $mailer->addReplyTo($replyTo, $replyToName);
} else {
  $mailer->addReplyTo(array($replyTo, $replyToName));
}

Furthermore you want to add try {} catch() {} code as needed to handle the Exception coming from JMail/PHPMailer.

More information:

Discussion of the issue on Github

Relevant topic in Joomla forums

2
  • 1
    Nice find. I wish Joomla provided pages like this for their updates
    – Lodder
    Apr 7, 2016 at 15:26
  • 2
    As per the edit made by hbit, this is an issue since Joomla 3.0. However, I can confirm, that up to Joomla 3.5, this problem does not occur with any form using the old code. Apr 8, 2016 at 10:26
3

I also got this error when the $replyTo variable was empty and had to use

if ( !empty($replyTo) ) {
  $mailer->addReplyTo($replyTo, $replyToName);
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.