Laravel – How to send mail using Amazon SES

larvavel, php framework

In this guide, we will explore how to send emails using Amazon Simple Email Service (SES) in a Laravel application. Amazon SES is a scalable and cost-effective email sending service that handles the complex details of email delivery. Laravel, a robust PHP framework, provides seamless ways to integrate with services like Amazon SES. By integrating Amazon SES into your Laravel application, you can send notification emails, marketing messages, or any other kind of correspondence, leveraging the high deliverability and scalability of Amazon SES. Follow along to set up and implement this powerful email solution.

Sending Mail using Laravel and AWS SES – Step-by-Step Guide

Step 1: Install the AWS SDK for PHP via Composer

To use AWS SES with Laravel, you need to install the AWS SDK for PHP via Composer. Run the following command to install the AWS SDK for PHP:

composer require aws/aws-sdk-php

Step 2: Set up AWS SES

To send email using AWS SES, you need to set up an AWS SES account and verify your email address or domain. You can find more information on setting up AWS SES here: https://docs.aws.amazon.com/ses/latest/DeveloperGuide/quick-start.html

Step 3: Configure Laravel to use AWS SES

Open the .env file in the root directory of your Laravel project and add the following lines:

MAIL_DRIVER=ses
MAIL_HOST=email-smtp.us-west-2.amazonaws.com
MAIL_PORT=587
MAIL_USERNAME=your_ses_smtp_username
MAIL_PASSWORD=your_ses_smtp_password
MAIL_ENCRYPTION=tls

Replace your_ses_smtp_username and your_ses_smtp_password with the SMTP credentials for your AWS SES account. You can find your SMTP credentials in the AWS SES SMTP settings.

See also  Useful tips for PHP developers using MySQL

Step 4: Send email using Laravel

You can now use Laravel’s built-in Mail class to send email using AWS SES. Here’s an example:

use Illuminate\Support\Facades\Mail;
use App\Mail\WelcomeEmail;

Mail::to('recipient@example.com')->send(new WelcomeEmail());

In this example, WelcomeEmail is a class that extends Laravel’s Mailable class and defines the email message. Consider creating Unit tests to ensure you don’t have regressions in the email functionality. You can find more information on defining email messages in Laravel here: https://laravel.com/docs/8.x/mail#creating-mailables

Amazon AWS SES Alternatives

SendGrid

SendGrid, now owned by Twilio, is a robust email service that seamlessly integrates with Laravel via API or SMTP relay. Its well-documented Laravel library makes the integration straightforward. In terms of cost, SendGrid offers a free tier that allows sending up to 100 emails per day. Paid plans start from $14.95/month, providing an array of additional features such as dedicated IPs and advanced analytics.

Mailgun

Mailgun offers high deliverability rates and is known for its powerful APIs, making it a great choice for developers. Laravel integration is facilitated through the Mailgun SDK or SMTP. The cost is based on the number of emails sent and received, with the first 5,000 emails free each month, then $0.80 per 1,000 emails thereafter. It’s worth noting that Mailgun also provides email validation services, which can help improve email deliverability.

Postmark

Postmark focuses on transactional email delivery with speedy, reliable service. Its Laravel package makes integration a breeze. Postmark’s pricing model is straightforward: $10 for 10,000 emails per month, with the first 100 emails per month free. They also offer a 45-day free trial. Postmark is a particularly good option for teams looking for detailed analytics and logs.

See also  Use PHP to Scrape Error & Bounced Emails from the EXIM Log and Add To a Blacklist

SendinBlue

SendinBlue (now Brevo) offers an all-in-one digital marketing platform, with capabilities extending beyond just email to include SMS and live chat. Its Laravel integration is done through SMTP or API. SendinBlue’s free tier allows for 300 emails per day, while their paid plans start from $25/month for 20,000 emails. This service could be an attractive option for businesses seeking a more comprehensive marketing solution.

Mailjet

Mailjet is an email service designed for both developers and marketers. It offers a Laravel package for easy integration. The pricing is quite competitive, with a free plan allowing 6,000 emails per month (200 emails per day limit), and paid plans starting from $9.65/month for 30,000 emails without daily sending limits.

That’s it! Your Laravel application is now set up to send email using AWS SES.

Support us & keep this site free of annoying ads.
Shop Amazon.com or Donate with Paypal

Leave a Comment