Message templates not always sent
Overview
There appears to be some subtle breakage in how message-templates are sent. I believe this is why the "Password Reset" emails aren't being sent (cc @pfigel @artfulrobot).
Reproduction steps
Setup a fake email service (eg MailHog)
Run this script:
function do_wfmsg_a() {
$msg = \Civi\WorkflowMessage\WorkflowMessage::create('petition_sign', [
'from' => '"Foo" <foo@bar.com>',
'contactId' => 204,
]);
$msg->setTo('demo@example.com');
return $msg->sendTemplate([
'messageTemplate' => [
'msg_subject' => 'My Subject ' . __FUNCTION__,
'msg_text' => 'Hello',
'msg_html' => '<p>Hello</p>',
]
]);
}
Observe whether the email is received
Current behaviour
The email is not actually delivered (circa 5.64.0).
Expected behaviour
The email is actually delivered (circa 5.63.3).
Comments
I did a git bisect
, and I believe it originates from:
https://github.com/civicrm/civicrm-core/commit/ba4b246234e4dd58e23050138455aec6497ac988
Probably related: When I watched this in the debugger, I noticed that CRM_Core_BAO_MessageTemplate::renderTemplateRaw()
calls WorkflowMessage::importAll()
. At this point, it wipes out the $model->to
property.