laravel send mail code example

Example 1: laravel mail create

php artisan make:mail OrderShipped --markdown=emails.orders.shipped

Example 2: send multiple mail in laravel

$emails = ['[email protected]', '[email protected]','[email protected]'];

Mail::send('emails.welcome', [], function($message) use ($emails)
{    
    $message->to($emails)->subject('This is test e-mail');    
});
var_dump( Mail:: failures());
exit;

Example 3: laravel mailable from

return (new Mail)
    ->to('[email protected]')
    ->from('[email protected]');

Example 4: laravel gmail send mail 2020

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=yourEmail@gmail.com
MAIL_PASSWORD=this code is generated read more down
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=yourEmail@gmail.com
MAIL_FROM_NAME=yourName
MAIL_LOG_CHANNEL=NULL

Example 5: laravel mail to specific email

$to = [
    [
        'email' => $email, 
        'name' => $name,
    ]
];
\Mail::to($to)->send(new \App\Mail\Hello);

Tags:

Php Example