实现 hook_mail
hook_mail($key, &$message, $params)
/** * Implements hook_mail(). */ function common_mail($key, &$message, $params) { switch ($key) { case 'test': { $message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed; delsp=yes'; $message['body'][] = new \Drupal\Component\Render\FormattableMarkup($params['content'], []); break; } } }
使用的时候
$message = \Drupal::service('plugin.manager.mail')->mail('common', 'test', $mail, $langcode, $params);