如何使用drupal_mail在drupal 6中发送HTML电子邮件?如何更改HTML标头以HTML格式显示电子邮件内容。
答案 0 :(得分:5)
<?php
hook_mail_alter(&$message) {
$message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed';
}
?>
答案 1 :(得分:2)
我知道这可能会迟到,但它可能对其他人有帮助。最好使用drupal_mail,然后在hook_mail而不是hook_mail alter中设置头文件。一个例子就像:
/*drupal_mail($module, $key, $to, $language, $params = array(), $from = NULL, $send = TRUE)
Lets say we call drupal_mail from somewhere in our code*/
$params = array(
'subject' => t('Client Requests Quote'),
'body' => t("Body of the email goes here"),
);
drupal_mail("samplemail", "samplemail_html_mail", "admin@mysite.com", language_default(), $params, "admin@mysite.com");
/*We now setup our mail format, etc in hook mail*/
function hook_mail($key, &$message, $params)
{
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;
}
如果您不清楚这一点,可以在My Blog
上找到相关的完整教程希望这会有所帮助 JK