开发者

How to send HTML email in drupal 6 using drupal_mail?

开发者 https://www.devze.com 2023-01-23 04:57 出处:网络
How to send HTML email in drupal 6 using drupal_mail ? How can I chan开发者_如何学Cge HTML header to show email contents in HTML.You can to set the header in hook_mail_alter()

How to send HTML email in drupal 6 using drupal_mail ? How can I chan开发者_如何学Cge HTML header to show email contents in HTML.


You can to set the header in hook_mail_alter()

<?php
hook_mail_alter(&$message) {    
    $message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed';
}
?>


i know this may be late, but it may help others. Its better to use drupal_mail and then set the headers in hook_mail instead of hook_mail alter. an example would be like:

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

If this is unclear to you, a complete tutorial on this can be found on My Blog

Hope this helps
JK

0

精彩评论

暂无评论...
验证码 换一张
取 消