Send email using SMTP with Amazon Simple Email Service

Posted by Vasilis on April 18, 2018

The AWS documentation has all the steps and a sample code to send an email with using PHPMailer.

In the code you have to replace path_to_sdk_inclusion with the path of autoload.php if you use composer.

Note: You have to comment or remove the line of the configuration set or else the code provided will not work. The line starts as $mail->addCustomHeader

The documentation includes the steps to fulfill all the prerequisites but in case you missed something you can check them in quick steps:


1 Get SMTP credentials

You will need to replace in the code smtp_username and smtp_password with your credecials. To generate them you go to and select SMTP Settings from the left menu.


2 Set Enpoint

Change $mail->Host to the appropriate region that you are using


3 Verify Sender's Email Address

On select Email Addresses and Verify a New Email Address. After submiting open the email that AWS send you and follow the verification link. Use this email to set $mail->setFrom and $mail->addAddress


Note: You can make the test using only verified email adresses, in order to send to other emails you have to Move outside the Sandbox


In case that there is an authentication error you can verify that the user of whom you use the credencials can use the Simple Email Service at Users