Chaining in mail broken ./ changed on fresh installed joomla 3.8.3

20 views
Skip to first unread message

Ruud van Lent

unread,
Jan 19, 2018, 9:52:29 AM1/19/18
to Joomla! General Development
Hi,

been troubleshooting a component where there was the infamous error 0.
as it turned out, the culprit was in the chaining of the mail. Now I got a report that one of my own plugins is showing the same error 0 behavior....
The following code which works okay on sites UPGRADED to Joomla 3.8.3 now is broken on sites that are FRESH INSTALLED with Joomla 3.8.3...

                    $mailer = JFactory::getMailer();
                    $config
= JFactory::getConfig();
                    $sender
= array(
                            $config
->get('mailfrom'),
                            $config
->get('fromname')
                   
);
                    $body
= "LOGFILE";
                    $body
.= "\n----------\n";
                    $body
.= file_get_contents($logFile);

                    $mailer
                       
->setSender($sender)
                       
->addReplyTo($sender)
                       
->addRecipient($config->get('mailfrom'))
                       
->setSubject("MAILLOG")
                       
->setBody($body)
                       
->isHTML(false);

                    $send
= $mailer->Send();


When removing the chaining in the code, everything works as expected...
This is the error that is thrown in the log file:
2018-01-12T09:50:04+00:00    WARNING SECRET-IP    deprecated    Joomla\CMS\Mail\Mail::add() will not catch phpmailerException objects as of 4.0.
2018-01-12T09:50:04+00:00    CRITICAL SECRET-IP    error    Uncaught \Throwable of type Error thrown. Stack trace: #0 /home/...THE FILE WITH THE $MAILER CODE IN IT...php

Can anybody shed a light?
As said, on upgraded Joomla installation, this works okay, it only happens on fresh installed sites!

Michael Babker

unread,
Jan 19, 2018, 9:59:32 AM1/19/18
to joomla-de...@googlegroups.com
All of the methods which allow you to add an email address to a message can either return an instance of $this or boolean false, it is advisable that you do not rely on method chaining.  Note that the method chaining on the addReplyTo and addRecipient methods is a deviation from the parent PHPMailer API which can only return booleans (setSender is a Joomla specific method).

If sites that were upgraded work OK but fresh installs do not, using the same data sets, this means the site has not been properly upgraded.  There were several changes in the JMail/Joomla\CMS\Mail\Mail class at 3.5.1 and 3.6.0 to account for the class silently absorbing error conditions.

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-general+unsub...@googlegroups.com.
To post to this group, send email to joomla-dev-general@googlegroups.com.
Visit this group at https://groups.google.com/group/joomla-dev-general.
For more options, visit https://groups.google.com/d/optout.

Ruud van Lent

unread,
Jan 19, 2018, 10:08:18 AM1/19/18
to Joomla! General Development
Top and thanks for the follow up!

So What I will do is refactor all my mailer code (in all my projects) and remove the chaining from it.

I will try to find out what went wrong with the upgrading as it is the same for all the sites I maintain.
Reply all
Reply to author
Forward
0 new messages