[英]How to send Html formatted mail instead of default email format in Drupal 8
How can we send a html formatted mail in Drupal 8 instead of default format that given by Drupal core. 我们如何以Drupal 8发送html格式的邮件,而不是Drupal核心提供的默认格式。 Such as default email format for user account creation, how can we send this in Html format? 例如用于创建用户帐户的默认电子邮件格式,我们如何以HTML格式发送此格式?
You can have a look at the HTML Mail module but the drupal 8 version is still in alpha :/ . 您可以看一下HTML Mail模块,但drupal 8版本仍在alpha:/中。
Another simple alternative is to implement hook_mail_alter
in order to : 另一个简单的选择是实现hook_mail_alter
以便:
The only thing to do now is to write some HTML in the messages, and this should do the job : 现在唯一要做的就是在消息中编写一些HTML,这应该可以完成工作:
/**
* Implements hook_mail_alter().
*/
function modulename_mail_alter(&$message) {
switch ($message['key']) {
case 'register_admin_created':
#case '<other HTML message id>':
#...
$message['headers']['Content-Type'] = 'text/html; charset=UTF-8;';
foreach ($message['body'] as $key => &$body) {
$body = new Drupal\Component\Render\FormattableMarkup($body, []);
}
break;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.