$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);
Emails are send to "test@example.com" (at least one)
No email is send.
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
Labels |
Added:
?
|
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"
Category | ⇒ | com_plugins |
Status | New | ⇒ | Discussion |
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
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
Status | Discussion | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2017-10-03 05:30:36 |
Closed_By | ⇒ | franz-wohlkoenig |
Closed_By | franz-wohlkoenig | ⇒ | joomla-cms-bot |
Set to "closed" on behalf of @franz-wohlkoenig by The JTracker Application at issues.joomla.org/joomla-cms/15993
closed as having Pull Request #18196
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.