Home > php > Sending Email with PHP, PHPMailer and Amazon SES

Sending Email with PHP, PHPMailer and Amazon SES

January 21st, 2012 Leave a comment Go to comments

Sending email with Amazon’s SES is easy. To get started you’ll need an AWS account with SES sending enabled.

This example uses PHPMailer and builds on some PHPMailer examples.


    require_once('PHPMailer/class.phpmailer.php');
    $to         = "someone@foo.com";
    $from       = "youremail@foo.com";
    $subject    = "a test subject";
    $body       = "email body content goes here";

    $mail       = new PHPMailer();
    $mail->IsSMTP(true);            // use SMTP

    //$mail->SMTPDebug  = 2;        // enables SMTP debug information (for testing)
                                    // 1 = errors and messages
                                    // 2 = messages only
    $mail->SMTPAuth   = true;                  // enable SMTP authentication
    $mail->Host       = "tls://email-smtp.us-east-1.amazonaws.com"; // Amazon SES server, note "tls://" protocol
    $mail->Port       = 465;                    // set the SMTP port
    $mail->Username   = "YourSESSMTPUserName";  // SES SMTP  username
    $mail->Password   = "YourSESSMTPPassword";  // SES SMTP password

    $mail->SetFrom($from, 'First Last');
    $mail->AddReplyTo($from,'First Last');
    $mail->Subject    = $subject;
    $mail->MsgHTML($body);
    $address = $to;
    $mail->AddAddress($address, $to);

    if(!$mail->Send()) {
      echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
      echo "Message sent!";
    }

For an example of using SSL with SES and PHPMailer see https://forums.aws.amazon.com/thread.jspa?threadID=82812

Categories: php Tags:
  1. No comments yet.
You must be logged in to post a comment.