BCC对于drupal邮件功能[关闭]


20

我正在使用Drupal 7,并专注于使用电子邮件选项。我正在使用转发模块。如何在drupal_mail()函数中添加密件抄送字段。

我的默认功能是

drupal_mail('forward', 'forward_page', trim($to), language_default(), $params, $params['from']);

Answers:


27

您需要的所有内容都在电子邮件标题数组中。

$params['headers'] = array(
    'Bcc' => 'bcc_email@example.com',
    'Cc' => 'cc_email@example.com',
);

这是包含bcc标头的drupal_mail()的示例实现。

$params = array(
    'body' => $body,
    'subject' => $subject,
    'headers' => array(
        'Bcc' => $header_bcc,
        'Cc' => $header_cc
    )
);

$email = drupal_mail('ModuleName', 'message_key', $to, LANGUAGE_NONE, $params, $from, true);

使用hook_mail(),您需要添加(谢谢@ clive):

/**
 * Implements hook_mail().
 */
function ModuleName_mail($key, &$message, $params) {
    switch ($key) {
        case 'message_key':
            $message['headers'] += $params['headers'];
    }
}

我们添加了代码,但是cc和bcc字段不起作用。请给出另一个解决方案。
sathish

3

您可以使用钩子邮件alter来更改或添加对cc和bcc邮件ID的更改,请参见示例:


/**
 * Implements hook_mail_alter().
 */
function hook_mail_alter(&$message) {
  $message['to'] = 'mail@gmail.com';
  $message['headers']['Bcc'] = 'Your mail ids goes here with comma seperation';
  $message['headers']['Cc'] = 'Your mail ids goes here with comma seperation';
}

您也可以在drupal_mail()的$ params数组中使用密件抄送和cc邮件ID:


$params = array(
  'body' => $body,
  'subject' => 'Your Subject',
  'headers' => array(
    'Cc' => 'Your mail ids goes here with comma seperation',
    'Bcc' => 'Your mail ids goes here with comma seperation',
  ),
);


2

你可以这样做:

$message['headers']['Bcc'] = 'email@address.com';

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.