How do I set BCC in the email I am sending? I am using Drupal 8. How can I add the BCC field in the mail function.

Using below code Bcc not working

$params['body'] = 'test body';
$params['subject'] = 'test subject';
$params['Bcc'] = 'test@gmail.com';
$message =  \Drupal::service('plugin.manager.mail')-&gt;mail('test', 'test_email_form', $to, $langcode, $params, $from);


hook_mail function code:

function mymodule_mail($key, &amp;$message, $params) {
  switch ($key) {
    case 'test_email_form':
      $message['headers']['Bcc'] = $params['Bcc'];
      break;
  }
}
Your hook_mail implementation needs to set the subject/body for the email to send; $params is just passed for context.

Given your first snippet, this should work:

function mymodule_mail($key, &amp;$message, $params) {
  switch ($key) {
    case 'test_email_form':
      $message['headers']['Bcc'] = $params['Bcc'];
      $message['subject'] = $params['subject'];
      $message['body'][] = $params['body'];
      break;
  }
}