Add an email in BCC

Created on 3 October 2023, about 1 year ago
Updated 13 March 2024, 8 months ago

Problem/Motivation

Hello,
I would like to add a notification as BCC to a supervisor everytime a BRITHDAY WISH is sent.
As i couldnt reach a solution to add BCC at:
$mailManager->mail($module, $key, $to, $langcode, $params, NULL, TRUE); (File: birthday_wish_mail.module)

Then i tryed to add this:
$to = 'myemail@comain.com';
$result = $mailManager->mail($module, $key, $to, $langcode, $params, NULL, TRUE);

But without sucess.

Do you have any idea how can I get this?

Thank you
SB

💬 Support request
Status

Fixed

Version

2.0

Component

Code

Created by

🇵🇹Portugal stelmo

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @stelmo
  • Assigned to rohitrajputsahab
  • Status changed to Needs review about 1 year ago
  • 🇮🇳India rohitrajputsahab Uttam Nagar, Delhi

    Hi @

    In the ".module" file, you can try like this.

    function birthday_wish_mail_mail($key, &$message, $params) {
    switch ($key) {
    // Send a simple message from the contact form.
    case 'send_birthday_wish_mail':
    $token_service = \Drupal::token();
    $language_manager = \Drupal::languageManager();
    $langcode = $message['langcode'];
    $variables = ['user' => $params['account']];

    $language = $language_manager->getLanguage($params['account']->getPreferredLangcode());
    $language_manager->setConfigOverrideLanguage($language);
    $mail_config = \Drupal::config('birthday_wish_mail.settings_advanced');

    $token_options = [
    'langcode' => $langcode,
    'callback' => 'birthday_wish_mail_mail_tokens',
    'clear' => TRUE,
    ];
    $message['subject'] .= PlainTextOutput::renderFromHtml($token_service->replace($mail_config->get('site_title'), $variables, $token_options));
    $message['body'][] = $token_service->replace($mail_config->get('site_value'), $variables, $token_options);
    $message['headers']['bcc'] = 'test@test.com';
    break;
    }
    }

  • 🇮🇳India rohitrajputsahab Uttam Nagar, Delhi

    The BCC option is added in the new version. Please check it and confirm whether it's working or not.

    composer require 'drupal/birthday_wish_mail:^2.0'

  • Status changed to Fixed 9 months ago
  • 🇮🇳India rohitrajputsahab Uttam Nagar, Delhi
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024