?
avatar bembelimen
bembelimen
12 May 2017

Steps to reproduce the issue

  • Open the index.php of your template
  • Insert the following code:
$app = JFactory::getApplication();
$testmail = 'test@example.com'; // Adjust to an email
$subject = 'Hello';
$body = 'there';
JFactory::getMailer()->sendMail($app->get('mailfrom'), $app->get('fromname'), $testmail, $subject, $body, true, $testmail, $testmail);
  • open the page to send the email

Expected result

Emails are send to "test@example.com" (at least one)

Actual result

No email is send.

Additional comments

The reason is: if you add an email address a second time (here we add it as CC and BCC) PHPMailer checks for duplicates and returns false in the "adding process" but no error or exception (see comment here: https://github.com/joomla/joomla-cms/blob/staging/libraries/vendor/phpmailer/phpmailer/class.phpmailer.php#L861 ). But Joomla! itself stops the process when a "adding function" returns "false". see: https://github.com/joomla/joomla-cms/blob/staging/libraries/joomla/mail/mail.php#L693-L711

So I think this checks should be rewritten in terms of exception/error handling instead of checking for false

avatar bembelimen bembelimen - open - 12 May 2017
avatar joomla-cms-bot joomla-cms-bot - change - 12 May 2017
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 12 May 2017
avatar mbabker
mbabker - comment - 12 May 2017

There's no guarantee that PHPMailer's option to throw Exceptions will always be enabled, so the API has to handle both Exception throwing and boolean false returns instead of relying on one state or the other. It gets trickier because as you pointed out PHPMailer isn't always returning a boolean false representing an error state.

avatar bembelimen
bembelimen - comment - 12 May 2017

Yep, I have no good solution myself, but I think, duplicate addresses should not stop the whole process (at least for bcc/cc).

Perhaps something like: if ($this->addCc($cc) === false && !$this->exceptions)

Or ignore bcc/cc "return false"

avatar franz-wohlkoenig franz-wohlkoenig - change - 13 May 2017
Category com_plugins
avatar franz-wohlkoenig franz-wohlkoenig - change - 13 May 2017
Status New Discussion
avatar ggppdk
ggppdk - comment - 13 May 2017

I remember finding this case some time ago, with sendmail aborting silently because of same address existing in CC or in BCC

I had to add checks to avoid duplicates,
e.g. a valid case that this happend is

  • you send emails to users usergroup A
  • you bcc to users in usergroup B

but some users may belong to both usergroups

and then you get the sendmail() to abortsiliently (no error shown or logged somewhere)

Looking at code of the methods return documentation, "false" does not always mean error

    /**
     * ....
     * @return boolean true on success, false if address already used or invalid in some way
     */
    public function addCC($address, $name = '')

Here it is Joomla 's JMail aborting silently and not PHPMailer ...

Perhaps something like: if ($this->addCc($cc) === false && !$this->exceptions)

Sounds good, since false with no exception means duplicate address

Or ignore bcc/cc "return false"

This is not a good option

avatar franz-wohlkoenig franz-wohlkoenig - change - 3 Oct 2017
Status Discussion Closed
Closed_Date 0000-00-00 00:00:00 2017-10-03 05:30:36
Closed_By franz-wohlkoenig
avatar joomla-cms-bot joomla-cms-bot - change - 3 Oct 2017
Closed_By franz-wohlkoenig joomla-cms-bot
avatar joomla-cms-bot joomla-cms-bot - close - 3 Oct 2017
avatar joomla-cms-bot
joomla-cms-bot - comment - 3 Oct 2017
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 3 Oct 2017

closed as having Pull Request #18196


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/15993.

Add a Comment

Login with GitHub to post a comment