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.
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
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 = "[email protected]";
$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;
}
?>
function Send_Mail($to,$subject,$body)
{
require 'class.phpmailer.php';
$from = "[email protected]";
$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 = "[email protected]";
$subject = "Test Mail Subject";
$body = "Hi<br/>Test Mail<br/>Amazon SES"; // HTML tags
Send_Mail($to,$subject,$body);
?>
require 'Send_Mail.php';
$to = "[email protected]";
$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 = "[email protected]"; // SMTP Username
$mail->Password = "Gmail Password"; // SMTP Password
$mail->Port = 465; // SMTP Port
$mail->Username = "[email protected]"; // SMTP Username
$mail->Password = "Gmail Password"; // SMTP Password
Hey! Nice Mailer Post
ReplyDeleteSimple yet powerful, great tutorial thank you srinivas :)
ReplyDeletenice info ..thanks for sharing...
ReplyDeleteHow to get the SMTP username and password
ReplyDeleteThis is pretty awesome
ReplyDeleteit been long you update blog? last time i using your facebook script for my tin tuc news website.. and it work perfect ..
ReplyDeletefor this email script .. is there any limitation of volume we can sent email out ?
thanks
I used this as an function so i could dynamically use it in my other pages.
ReplyDeleteI 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()
Great post once again Sri. Keep up the good work!
ReplyDeleteNice One
ReplyDeleteis this work $mail->SetFrom($from, 'From Name');
when i used it take name of the email id not taking underspecified name
thanks for this toturial
ReplyDeletehey post something new :P
ReplyDeleteAwesome, I am agree with the view of Jonathan that mail=new mail();
ReplyDeleteregistration->($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()
nice tutorial dude
ReplyDeleteAwesome
ReplyDeleteHi
ReplyDeletePlease 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, '[email protected]');
$mail->AddReplyTo($from,'[email protected]');
$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
Hello
ReplyDeleteI 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.
What's the windows live smtp?
ReplyDeleteEveryone collaborated well. Hats off to all.
ReplyDeleteThis is great! Would it be easy to collect reports analytics (opened, clicked, unopened) from mails that send?
ReplyDeletethanks for this toturial
ReplyDeleteHello, for this work for 1-1 mail, but how would it be in order to send bulk mails?
ReplyDeleteNO SEND MAIL
ReplyDeleteGMAIL ACCOUNT
PORT 587
need help to use amazon ses in php
ReplyDeleteOkay, that's the SMTP route. How does one do it the REST-ful API route?
ReplyDeletedo we need edit php.ini with above changes? because not working in both cases-thanks
ReplyDeletehi admin
ReplyDeletei cant send or receive any emails with amazon ses
plz help me
is this technique is slow than using ses library ? please reply if anyone has idea
ReplyDeletethanks
ReplyDeletewhat is the name of database ?
ReplyDeleteNice Thanks
ReplyDelete