我在使用 drupal_mail() 时遇到问题。我收到了电子邮件,但主题和正文为空。
Drupal 版本 7
下面的代码
$params = array(
'subject' => t('Client Requests Quote'),
'body' => t("Body of the email goes here"),
);
drupal_mail("samplemail", "samplemail_html_mail", "email@email.com", language_default(), $params, "email@email.com", TRUE);
我什至用下面的钩子试过了,我得到了同样的结果。
function hook_mail($key, &$message, $params) {
switch ($key) {
case 'samplemail_html_mail':
/*
* Emails with this key will be HTML emails,
* we therefore cannot use drupal default headers, but set our own headers
*/
/*
* $vars required even if not used to get $language in there since t takes in: t($string, $args = array(), $langcode = NULL) */
$message['subject'] = t($params['subject'], $var, $language->language);
/* the email body is here, inside the $message array */
$body = "<html><body>
<h2>HTML Email Sample with Drupal</h2>
<hr /><br /><br />
{$params['body']}
</body></html>";
$message['body'][] = $body;
$message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed';
break;
}
}
drupal_mail_system() 有效,但它以纯文本形式出现。