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?
Joomla Stack Exchange is a question and answer site for Joomla! administrators, users, developers and designers. It only takes a minute to sign up.
Sign up to join this communityIf 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.
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:
I also got this error when the $replyTo variable was empty and had to use
if ( !empty($replyTo) ) {
$mailer->addReplyTo($replyTo, $replyToName);
}