Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.0] Missing mail template not handled correctly #36478

Closed
BrainforgeUK opened this issue Dec 29, 2021 · 3 comments
Closed

[4.0] Missing mail template not handled correctly #36478

BrainforgeUK opened this issue Dec 29, 2021 · 3 comments

Comments

@BrainforgeUK
Copy link
Contributor

Steps to reproduce the issue

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();

Expected result

Sensible error message saying template does not exist

Actual result

Load of PHP notices and a 'Message body empty' warning.

System information (as much as possible)

Additional comments

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();
@PhilETaylor

This comment was marked as abuse.

@PhilETaylor

This comment was marked as abuse.

@richard67
Copy link
Member

Closing as having a pull request. Please test #36489 . Thanks in adcance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants