Because of the way Drupal handles mail, adding the subject and body in the params array of \Drupal\Core\Mail\MailManager::mail() method will not add them to the mail subject and body.
We need to use a hook_mail / hook_mail_alter functions to move the subject and body from the params array to the subject/body accordingly.
/**
* Implements hook_mail_alter() for the rules module.
*
* Extract subject and body from emails and set them for mailer.
*/
function rules_mail_alter(&$message) {
if ($message['module'] == 'rules') {
$message['subject'] = !empty($message['params']['subject']) ? $message['params']['subject'] : '';
if ($message['key'] === 'rules_action_mail_rules_send_email') {
$message['body'] = !empty($message['params']['message']) ? array($message['params']['message']) : array();
}
else {
$message['body'] = !empty($message['params']['body']) ? array($message['params']['body']) : array();
}
}
}
This is of course a bug with drupal that will hopefully be fixed with 1346036.
The problem is that this issue is aimed at Drupal 8.2.x
I think it would be best to give a solution for this issue in the context of rules for 8.0.x and 8.1.x
Comments
Comment #2
tr commentedThis was fixed a long time ago, by #2702159: System send email issues on Drupal 8