Try to send mail using a mail template which does not exist.
$mailer = new MailTemplate('com_bftest.invalidtemplateid', $language);
$mailer->addRecipient($templateData['emailto'], $templateData['emailtoname']);
$mailer->setReplyTo($templateData['replytoemail'], $templateData['replytoname']);
$mailer->addTemplateData($templateData);
$sent = $mailer->send();
Sensible error message saying template does not exist
Load of PHP notices and a 'Message body empty' warning.
Be better to add a getInstance() static method to MailTemplate which would allow this
$mailer = MailTemplate::getInstance('com_bftest.invalidtemplateid', $language);
if (empty($mailer))
{
... take some action ...
}
$mailer->addRecipient($templateData['emailto'], $templateData['emailtoname']);
$mailer->setReplyTo($templateData['replytoemail'], $templateData['replytoname']);
$mailer->addTemplateData($templateData);
$sent = $mailer->send();
Can do this as a workaround - downside MailTemplate::getTemplate() gets called twice.
$test = MailTemplate::getTemplate($templateId, $language);
if (empty($mail))
{
... take some action ...
}
$mailer = new MailTemplate('com_bftest.invalidtemplateid', $language);
$mailer->addRecipient($templateData['emailto'], $templateData['emailtoname']);
$mailer->setReplyTo($templateData['replytoemail'], $templateData['replytoname']);
$mailer->addTemplateData($templateData);
$sent = $mailer->send();
Labels |
Removed:
?
|
Labels |
Added:
No Code Attached Yet
|
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2021-12-30 08:07:09 |
Closed_By | ⇒ | richard67 |
The problem is that, mails can come from anywhere, Admin, Frontend, CLI etc... So the correct thing would be an Exception, but that is too hard on a "user trying to send a contact form, formatted by a non existing mail template) and equally, in /administrator/ a "error" message can be displayed in the admin console, and for CLI an exception...
To display those messages has to be done outside of the
MailTemplate
class - which is only concerned about compiling and sending the mail.therefore I would just say that
$mailer->send()
should return false, with no other error messagesor just throw an Exception and expect 3PD to deal with catching it?