1

I am sending email programmatically and I am using plugin.manager.mail to send email, I want to add a CC ó BCC.

Do you know the way to achieve it?

1 Answer 1

2

What you want to do is ensure you are defining a message type in your custom module, you can then target the message within a hook_mail_alter() to add the desired CC or BCC.

function MYMODULE_mail_alter(array &$message) {
  $bccEmail = '[email protected]';

  if ($message['xxx'] == 'xxx') {
    $existingBcc = isset($message['headers']['Bcc']) ? $message['headers']['Bcc'] : '';
    $message['headers']['Bcc'] = implode(' ', array_merge(
      explode(' ', $existingBcc), [$bccEmail])
    );
  }
}

https://git.drupalcode.org/project/bcc/-/blob/8.x-3.x/bcc.module has an example of adding a bcc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.