AWS Code Sample


Send_Email_SMTP.php demonstrates how to send email through the Amazon SES SMTP interface.

<?php /** * Copyright 2010-2019, Inc. or its affiliates. All Rights Reserved. * * This file is licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. A copy of * the License is located at * * * * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ // Modify the path in the require statement below to refer to the // location of your Composer autoload.php file. require 'path_to_sdk_inclusion'; // Instantiate a new PHPMailer $mail = new PHPMailer; // Tell PHPMailer to use SMTP $mail->isSMTP(); // Replace with your "From" address. // This address must be verified with Amazon SES. $mail->setFrom('', 'Sender Name'); // Replace with a "To" address. If your account // is still in the sandbox, this address must be verified. // Also note that you can include several addAddress() lines to send // email to multiple recipients. $mail->addAddress('', 'Recipient Name'); // Replace smtp_username with your Amazon SES SMTP user name. $mail->Username = 'smtp_username'; // Replace smtp_password with your Amazon SES SMTP password. $mail->Password = 'smtp_password'; // Specify a configuration set. If you do not want to use a configuration // set, comment or remove the next line. $mail->addCustomHeader('X-SES-CONFIGURATION-SET', 'ConfigSet'); // If you're using Amazon SES in a region other than US West (Oregon), // replace with the Amazon SES SMTP // endpoint in the appropriate region. $mail->Host = ''; // The subject line of the email $mail->Subject = 'Amazon SES test (SMTP interface accessed using PHP)'; // The HTML-formatted body of the email $mail->Body = '<h1>Email Test</h1> <p>This email was sent through the <a href="">Amazon SES</a> SMTP interface using the <a href=""> PHPMailer</a> class.</p>'; // Tells PHPMailer to use SMTP authentication $mail->SMTPAuth = true; // Enable TLS encryption over port 587 $mail->SMTPSecure = 'tls'; $mail->Port = 587; // Tells PHPMailer to send HTML-formatted email $mail->isHTML(true); // The alternative email body; this is only displayed when a recipient // opens the email in a non-HTML email client. The \r\n represents a // line break. $mail->AltBody = "Email Test\r\nThis email was sent through the Amazon SES SMTP interface using the PHPMailer class."; if (!$mail->send()) { echo "Email not sent. ", $mail->ErrorInfo, PHP_EOL; } else { echo "Email sent!", PHP_EOL; }

Sample Details

Service: ses

Last tested: 2018-09-20

Author: jschwarzwalder (AWS)

Type: full-example

On this page: