Sending emails using Laravel is quite easy. All you need to do is to configure your
MAILER service properly. In this simple tutorial I am going to show you two methods to configure your Laravel application to send emails with
Amazon AWS SES (Simple Emailing Service).
- A working Laravel Applicaiton
- A working set of
AWS_SECRET_ACCESS_KEYparameters. These parameters are required to send email via SES.
Note: The same set of
access key idand
secret access keycan also be used for sending email via Amazon SMPT
- Mailing Writables as explained in the Laravel documentation
Steps to configure Laravel Application to Send Email with Amazon AWS SES in Laravel
Method 1 – Configure SES as Mailer
- Open and edit your
.envfile which is found in the root folder of your Laravel Application
- Add or update your
MAIL_MAILERsettings, to look like the following
Add the following settings to
Hint: You can remove all other MAIL specific settings such as MAIL_HOST, MAIL_PORT etc from
config/mail.phpand set default mailer to
... 'default' => env('MAIL_MAILER', 'ses'), ...
... 'default' => env('MAIL_MAILER', 'ses'), 'ses' => [ 'key' => env('AWS_ACCESS_KEY_ID'), 'secret' => env('AWS_SECRET_ACCESS_KEY'), 'region' => env('AWS_DEFAULT_REGION'), ], ...
Method 2 – Configure Amazon SMTP
If you have got Amazon SMTP settings you can add these smtp settings directly to .env file. In this method you don’t need to edit config/mail.php or config/services.php file of your Laravel Application. Just set in .env file as:
MAIL_MAILER=smtp MAIL_HOST=email-smtp.us-east-1.amazonaws.com MAIL_POR=587 MAIL_USERNAME=xxxxxxxxxxxxxxx MAIL_PASSWORD=xxxxxxxxxxxxxxx MAIL_ENCRYPTION=tls
Following above methods your Laravel application should be able to send messages via Amazon SES or Amazon SMTP service.
- How to Create folders recursively in Laravel (with Example)
- Laravel 8/9 Cron Job Task Scheduling Tutorial with examples
- How to Create Custom Log File in Laravel
- How to Clear cache in Laravel 9/8/7/6/5
- CSV Content Validation with FormRequest Rules in Laravel