Sending Email with Amazon SES SMTP and PHPMailer
We use Amazon SES to send email from some of our clients' web applications. Recently, we developed a web application for a company who wanted to host the app on their own server. In this case Amazon SES SMTP provides a security (and possibly performance) advantage over the PHP SDK we were using. The code below is an example of how to send email using PHPMailer & Amazon SES SMTP.
Download Files (25KB)
<?php
//include phpmailer
require_once('class.phpmailer.php');
//SMTP Settings
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "email-smtp.us-east-1.amazonaws.com";
$mail->Username = "SMTP-Username";
$mail->Password = "SMTP-Password";
//
$mail->SetFrom('verified@address.com', 'Sender Name'); //from (verified email address)
$mail->Subject = "Email Subject"; //subject
//message
$body = "This is a test message.";
$body = eregi_replace("[]",'',$body);
$mail->MsgHTML($body);
//
//recipient
$mail->AddAddress("contact@recipient.com", "Test Recipient");
//Success
if ($mail->Send()) {
echo "Message sent!"; die;
}
//Error
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
}
?>
Categories
· Mobile (1) · Projects (60) · Tutorials (14) · PHP (14) · jQuery (5) · MySQL (4)
View by date
· View All · March 2013 · February 2013 · October 2012 · September 2012 · August 2012 · July 2012 · May 2012 · March 2012 · February 2012 · January 2012 · December 2011 · November 2011 · October 2011 · September 2011 · July 2011 · June 2011 · May 2011 · April 2011 · March 2011 · February 2011 · January 2011 · December 2010 · November 2010 · October 2010 · September 2010 · July 2010 · May 2010 · April 2010 · February 2010 · January 2010 · November 2009 · August 2009 · July 2009 · May 2009