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:
- 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 theconfig/mail.php
configuration file, typically including SMTP settings. - Using the Mail Facade:
In your controller or wherever you’re sending emails from, import theMail
facade at the top of your file:
use Illuminate\Support\Facades\Mail;
- Setting CC Recipients:
To add CC recipients to your email, use thecc()
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.
- Setting BCC Recipients:
Similarly, to add BCC recipients, use thebcc()
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.
- Using Arrays for Multiple Recipients:
Alternatively, you can pass an array of email addresses to thecc()
andbcc()
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.