9lessons programming blog
Loading Search
Tuesday, February 21, 2012

Amazon Simple Email Service SMTP using PHP Mailer.

I have been working with labs.9lessons application hosted at Amazon Web Services. Few days back I had enabled email notification system using Amazon Simple Email Service SMTP implemented with PHP Mailer class, I hope the following tutorial will help you to enable email notification system for your web projects.

Amazon Simple Email Service SMTP using PHP Mailer

Download Script     Live Demo

The tutorial contains five PHP files in that three are PHPmailer files other SMTP config files.
class.phpmailer.php // PHP Mailer library
class.smtp.php
class.pop3.php
Send_Mail.php // SMTP configer
index.php // Start Page

Send_Mail.php
Here you have to give Amazom SES SMTP credentials.
<?php
function Send_Mail($to,$subject,$body)
{
require 'class.phpmailer.php';
$from = "from@email.com";
$mail = new PHPMailer();
$mail->IsSMTP(true); // SMTP
$mail->SMTPAuth   = true;  // SMTP authentication
$mail->Mailer = "smtp";
$mail->Host= "tls://email-smtp.us-east.amazonaws.com"; // Amazon SES
$mail->Port = 465;  // SMTP Port
$mail->Username = "Amazon SMTP Username";  // SMTP  Username
$mail->Password = "Amazon SMTP Password";  // SMTP Password
$mail->SetFrom($from, 'From Name');
$mail->AddReplyTo($from,'9lessons Labs');
$mail->Subject = $subject;
$mail->MsgHTML($body);
$address = $to;
$mail->AddAddress($address, $to);

if(!$mail->Send())
return false;
else
return true;

}
?>

index.php
Here called Send_Mail function and passing to, subject and body values.
<?php
require 'Send_Mail.php';
$to = "to@gmail.com";
$subject = "Test Mail Subject";
$body = "Hi<br/>Test Mail<br/>Amazon SES"; // HTML  tags
Send_Mail($to,$subject,$body);
?>

GMail SMTP
You have to modify following line in above Send_Mail.php code, gmail allow per day only 250 mail limit.
$mail->Host= "tls://smtp.gmail.com"; // GMail SMTP
$mail->Port = 465;  // SMTP Port
$mail->Username = "Username@gmail.com";  // SMTP  Username
$mail->Password = "Gmail Password";  // SMTP Password

Share this post

Comments
{ 18 comments }
Sandeep Verma said...

Hey! Nice Mailer Post

Bharat said...

Simple yet powerful, great tutorial thank you srinivas :)

fuad uii said...

nice info ..thanks for sharing...

Anonymous said...

How to get the SMTP username and password

Ferrari said...

This is pretty awesome

tin tuc said...

it been long you update blog? last time i using your facebook script for my tin tuc news website.. and it work perfect ..
for this email script .. is there any limitation of volume we can sent email out ?
thanks

Jonathan said...

I used this as an function so i could dynamically use it in my other pages.
I can always give an example of how i did that if people want.

only by using:

mail=new mail();
registration->($from,$subject,$body,$to);

I made on with an array function wo str_recplaces tekst in the body so people could use custom tags like [USER] in the $body=array()

Nimsrules said...

Great post once again Sri. Keep up the good work!

Godwin said...

Nice One

is this work $mail->SetFrom($from, 'From Name');

when i used it take name of the email id not taking underspecified name

mxtdn said...

thanks for this toturial

Mikel said...

hey post something new :P

website design bangkok said...

Awesome, I am agree with the view of Jonathan that mail=new mail();
registration->($from,$subject,$body,$to);

I made on with an array function wo str_recplaces tekst in the body so people could use custom tags like [USER] in the $body=array()

Mohit Bumb said...

nice tutorial dude

Anonymous said...

Awesome

Yuvraj said...

Hi

Please help me I am trying set this up,

this is my Send_Mail.php


IsSMTP(true); // SMTP
$mail->SMTPAuth = true; // SMTP authentication
$mail->Mailer = "smtp";
$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 = "AKIAJ3S57QUFQKS4A7VQ"; // SES SMTP username
$mail->Password = "Avl2i0lbSlC9ZSw2l7477f0urgC/AyZNkZ51r7sQrEF/"; // SES SMTP password
$mail->SetFrom($from, 'yuvraj61184@gmail.com');
$mail->AddReplyTo($from,'yuvraj61184@gmail.com');
$mail->Subject = $subject;
$mail->MsgHTML($body);
$address = $to;
$mail->AddAddress($address, $to);


if(!$mail->Send()){
return "failed";
}
else{
return "success";
}


this is my index.php




I have created an account with amazon ses and taken the smtp credentials.

I have a godaddy hosting, and I have added SPF record : v=spf1 mx include:amazonaws.com include:amazonses.com ~all

how to fix this and where can I see the error logs?

But I am unable to send the mail, can you please guide me its urgent

Quantum Scalar Pendant said...

Hello
I am using this script on normal web hosting its working.
same script i am using on my VPS its not working.
may i know anything i need to do for this script in my vps??

Please help me ASAP.

Thank you.

Anonymous said...

What's the windows live smtp?

Facebook Apps Development said...

Everyone collaborated well. Hats off to all.

Post a Comment

Subscribe now!Recent Posts

Categories

Subscribe now!Popular Posts

People Says

@9lessons thank you for the great tutorials, we truly appreciate your contributions to the design community.

Smashing Magazine
After developing a site you’ll require a web hosting plan to host your site, a recommended host is justhost.com which operates a LAMP environment and has been established a number of years.

Like Me