It is possible that in your application, you may need to send emails from different platforms. For example, you can send some emails with your current email provider, and others with Mandrillapp.
Well, it’s easier than you expect.
Let’s see an example with Mandrillapp and Brevo (two well-known email providers).
The first step is to edit the file config/mail.php and add a new entry for each provider (mandrillapp and brevo):
'smtp' => [ 'transport' => 'smtp', 'host' => env('MAIL_HOST', 'smtp.mailgun.org'), 'port' => env('MAIL_PORT', 587), 'encryption' => env('MAIL_ENCRYPTION', 'tls'), 'username' => env('MAIL_USERNAME'), 'password' => env('MAIL_PASSWORD'), 'timeout' => null, 'local_domain' => env('MAIL_EHLO_DOMAIN'), ], 'mandrillapp' => [ 'transport' => 'smtp', 'host' => env('MANDRILL_HOST', 'smtp.mailgun.org'), 'port' => env('MANDRILL_PORT', 587), 'encryption' => env('MANDRILL_ENCRYPTION', 'tls'), 'username' => env('MANDRILL_USERNAME'), 'password' => env('MANDRILL_PASSWORD'), ], 'brevo' => [ 'transport' => 'smtp', 'host' => env('BREVO_HOST', 'smtp.mailgun.org'), 'port' => env('BREVO_PORT', 587), 'encryption' => env('BREVO_ENCRYPTION', 'tls'), 'username' => env('BREVO_USERNAME'), 'password' => env('BREVO_PASSWORD'), ],
Don’t forget to create all these keys in your .env file!
To send an email with Mandrillapp, you just need to do the following:
Mail::mailer('mandrillapp')->to($to)->send($mailable);
Where:
- $to – is the recipient.
- $mailable – it is the mailable you want to send.
And, of course, to send it with Brevo just do as follows:
Mail::mailer('brevo')->to($to)->send($mailable);