2010-10-29 55 views
4

如何使用drupal_mail在drupal 6中發送HTML電子郵件?如何更改HTML標題以HTML格式顯示電子郵件內容。如何使用drupal_mail在drupal 6中發送HTML電子郵件?

+1

谷歌搜索止跌回升[如何發送HTML電子郵件與drupal_mail()?](http://drupal.org/node/358855) – 2010-10-29 18:29:07

+0

沒有得到解決方案:( – Dev 2010-10-29 18:43:17

回答

5

您可以設置標題中hook_mail_alter()

<?php 
hook_mail_alter(&$message) {  
    $message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed'; 
} 
?> 
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", "[email protected]", language_default(), $params, "[email protected]"); 

/*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

相關問題