How To CC And BCC Emails In Laravel 11

In Laravel 11, managing CC (carbon copy) and BCC (blind carbon copy) email addresses is straightforward when sending emails using the built-in Mail facade. To include CC and BCC recipients, you can utilize the cc() and bcc() methods provided by the Mail class. Here’s how you can set CC and BCC email addresses in Laravel 11 Mail:

  1. Basic Email Sending:
    Before diving into CC and BCC, ensure your Laravel application is properly configured to send emails. You should have your mail driver set up in the config/mail.php configuration file, typically including SMTP settings.
  2. Using the Mail Facade:
    In your controller or wherever you’re sending emails from, import the Mail facade at the top of your file:
   use Illuminate\Support\Facades\Mail;
  1. Setting CC Recipients:
    To add CC recipients to your email, use the cc() method before sending the email:
   Mail::to($recipient)
       ->cc($ccRecipient1)
       ->cc($ccRecipient2)
       ->send(new YourMailable());

You can chain multiple cc() calls to add multiple CC recipients.

  1. Setting BCC Recipients:
    Similarly, to add BCC recipients, use the bcc() method:
   Mail::to($recipient)
       ->bcc($bccRecipient1)
       ->bcc($bccRecipient2)
       ->send(new YourMailable());

Just like with CC, you can chain multiple bcc() calls to add multiple BCC recipients.

  1. Using Arrays for Multiple Recipients:
    Alternatively, you can pass an array of email addresses to the cc() and bcc() methods:
   $ccRecipients = [$ccRecipient1, $ccRecipient2];
   $bccRecipients = [$bccRecipient1, $bccRecipient2];

   Mail::to($recipient)
       ->cc($ccRecipients)
       ->bcc($bccRecipients)
       ->send(new YourMailable());

This is useful when dealing with multiple recipients at once.

By following these steps, you can easily include CC and BCC recipients when sending emails using Laravel 11 Mail, allowing you to effectively manage the delivery of your messages.

Leave a Reply