How to send cc mail in laravel 5.5
In Laravel 5.5, you can send a CC (Carbon Copy) email using the Mail
facade or the Illuminate\Support\Facades\Mail
class. Here are a few ways to do it:
Method 1: Using the Mail
facade
use Illuminate\Support\Facades\Mail;
Mail::to('[email protected]')
->cc('[email protected]')
->send(new MyEmailNotification());
In this example, MyEmailNotification
is a custom email notification class that extends Illuminate\Notifications\Mailable
.
Method 2: Using the Mail
class
use Illuminate\Support\Facades\Mail;
$mail = Mail::raw('Hello, world!', function ($message) {
$message->to('[email protected]')
->cc('[email protected]');
});
$mail->send();
In this example, we create a new Mail
instance and pass a raw email message to it. We then set the to
and cc
recipients using the to
and cc
methods, respectively.
Method 3: Using a custom email notification class
namespace App\Notifications;
use Illuminate\Notifications\Mailable;
use Illuminate\Notifications\Notification;
class MyEmailNotification extends Mailable
{
public function build()
{
return $this->to('[email protected]')
->cc('[email protected]');
}
}
In this example, we define a custom email notification class MyEmailNotification
that extends Illuminate\Notifications\Mailable
. We override the build
method to set the to
and cc
recipients.
To send the email, you can use the Mail
facade or the Illuminate\Support\Facades\Mail
class:
use Illuminate\Support\Facades\Mail;
Mail::to('[email protected]')
->cc('[email protected]')
->send(new MyEmailNotification());
Make sure to configure your email settings in the config/mail.php
file and the config/auth.php
file (if you're using authentication).