I need to send some test emails from Laravel and want to do it, without Mail classes, etc. I usually use the Mail::send()
function for this and it works fine. However, I've just realized that cc/bcc recipients don't seem to work when using this form.
In case useful to know, I'm using sendmail.
$result=Mail::send('site.emails.empty-template', ['msg'=>"Hi this is a test msg"], function ($message) {
$message->from('[email protected]');
$message->subject("A test email");
$message->to("[email protected]");
$message->cc("[email protected]");
$message->bcc(["[email protected]","[email protected]]);
});
You can use Mail::send
method, and by using this, you can customize your subject
and body
.
$options = [
'cc' => '[email protected]',
'bcc' => ['[email protected]', '[email protected]'],
];
Mail::send([], [], function ($message) use ($email, $options) {
$message->to($email)
->cc($options['cc'])
->bcc($options['bcc'])
->subject('A test emai')
->setBody('This is the email content.', 'text/html');
});
OR
you may use this one
Create a new mailable class
php artisan make:mail MyMail
class MyMail extends Mailable
{
use Queueable, SerializesModels;
public function __construct()
{
//
}
public function build()
{
return $this->view('emails.my-email')
->cc(['[email protected]']);
}
}
Use class to send the email
Mail::to($email)->send(new MyMail());