Categories
Amazon Web Services PHP

Send Email Using Amazon Simple Email Service (SES) in PHP

Hello Everyone,

In this blog, I will demonstrate to you, How to send Emails using Amazon Simple Email Service (SES) in PHP. We will use PHP Mailer library to send email. PHP Mailer simplifies the process of sending emails and it is very easy to use.

Prerequisites

Before Starting to send email, We have to perform following tasks:

1 . Verify your Email address to Amazon SES

Before sending email, You have to verify your sender email address which you using for sending email. If you want to use your Gmail then you can verify your Gmail and start sending an email using amazon SMTP.

But, Remember one thing If your AWS account is new than Amazon put your SES account in Sandbox. In Sandbox, you can use all features of SES but with some restrictions and those are :-

  • You can only send mail to verified email addresses and domains.
  • You can send a maximum of 200 messages per 24-hour period.
  • You can send a maximum of 1 message per second.

For moving out your SES account from Sandbox . You have to put request in Amazon Support center with some details . You can check out the process here – Click here

To Check if your account is in the sandbox

  1. Open the Amazon SES console – Click here
  2. Use the Region selector to choose an AWS Region
  3. In the navigation pane, under Email Sending, choose Sending Statistics
  4. If your account is still in the sandbox in the AWS Region that you selected, you see a banner at the top of the page that resembles the example in the following image.

Process to verify your email address :-

  1. Open the Amazon SES console – Click here
  2. Use the Region selector to choose an AWS Region
  3. In the navigation pane, under Identity Management, choose Email Addresses
  4. Click on Verify a New Email Address. Enter your sender or receiver email (if your account in the sandbox).

Amazon sends a verification email to your email address. You can verify it from there. You can check verification status in the Email Addresses.

2 . Get your SMTP Credentials

You need an Amazon SES SMTP user name and password to access the Amazon SES SMTP interface. Your SMTP credentials are not the same as your AWS credentials.

Process to get your SMTP Credentials :-

  1. Open the Amazon SES console – Click here
  2. Use the Region selector to choose an AWS Region
  3. In the navigation pane, under Email Sending, choose SMTP Settings.
  4. Click on Create My SMTP Credentials.
  5. Enter your IAM Username
  6. On the next page, You can download your SMTP Credentials with the username and password.

3 . Send mail using PHP Mailer

For Sending mail first you have to install PHP Mailer library in your project. For installation you have to enter below command in composer

After PHP Mailer library installation.

Get Server name and Port for sending email from SMTP Settings in the navigation pane under Email Sending.

For sending email, You can use below code :-

Don’t forget to change the values.

After sending mail you get the Email ‘sent message’ or an error message. You can sort out the error message when you read it properly or if you won’t then you can comment it in the blog. I will try to sort out your error.

Conclusion

I hope, Now you can send email . If you can’t understand something in this blog or you got an error in code, You can watch my video tutorial which will help you.

I would like to hear your thoughts or suggestions in the comment section.

Leave a Reply

Your email address will not be published. Required fields are marked *