How To Set CC And BCC Email Addresses In Laravel Mail

How To Set CC And BCC Email Addresses In Laravel Mail

Here are the steps on how to set CC and BCC email addresses in Laravel Mail:

  1. Open your Laravel project’s config/mail.php file.
  2. In the mailers array, find the mailer that you want to use to send the email.
  3. Add the cc and bcc keys to the mailer’s configuration.
  4. The cc key should contain an array of email addresses that you want to CC.
  5. The bcc key should contain an array of email addresses that you want to BCC.

For example, the following code will set the CC and BCC email addresses for the smtp mailer:

PHP

'smtp' => [
    'host' => 'smtp.gmail.com',
    'port' => 465,
    'username' => 'your_email@gmail.com',
    'password' => 'your_password',
    'encryption' => 'ssl',
    'cc' => ['cc@example.com'],
    'bcc' => ['bcc@example.com'],
],

Once you have set the CC and BCC email addresses, you can send an email using the Mail::send() method. For example:

PHP

Mail::send('emails.welcome', ['name' => $user->name'], function ($message) {
    $message->to($user->email);
    $message->cc('cc@example.com');
    $message->bcc('bcc@example.com');
});

This code will send an email to the user’s email address, with the CC and BCC addresses set to the specified email addresses.

For more posts like this click here.

Leave a Reply