【问题标题】:How to send HTML email in drupal 6 using drupal_mail?如何使用 drupal_mail 在 drupal 6 中发送 HTML 电子邮件?
【发布时间】:2010-10-29 18:28:16
【问题描述】:

如何使用 drupal_mail 在 drupal 6 中发送 HTML 电子邮件?如何更改 HTML 标头以 HTML 格式显示电子邮件内容。

【问题讨论】:

标签: drupal-6


【解决方案1】:

您可以在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", "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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-26
      • 2021-01-25
      • 2011-01-01
      相关资源
      最近更新 更多