Amazon Simple Email Service SMTP using PHP Mailer.
Wall Script
Wall Script
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 = "[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);
?>

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
web notification

30 comments:

  1. Simple yet powerful, great tutorial thank you srinivas :)

    ReplyDelete
  2. nice info ..thanks for sharing...

    ReplyDelete
  3. How to get the SMTP username and password

    ReplyDelete
  4. 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

    ReplyDelete
  5. 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()

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

    ReplyDelete
  7. Nice One

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

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

    ReplyDelete
  8. 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()

    ReplyDelete
  9. 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, '[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

    ReplyDelete
  10. 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.

    ReplyDelete
  11. What's the windows live smtp?

    ReplyDelete
  12. Everyone collaborated well. Hats off to all.

    ReplyDelete
  13. This is great! Would it be easy to collect reports analytics (opened, clicked, unopened) from mails that send?

    ReplyDelete
  14. Hello, for this work for 1-1 mail, but how would it be in order to send bulk mails?

    ReplyDelete
  15. NO SEND MAIL

    GMAIL ACCOUNT
    PORT 587

    ReplyDelete
  16. need help to use amazon ses in php

    ReplyDelete
  17. Okay, that's the SMTP route. How does one do it the REST-ful API route?

    ReplyDelete
  18. do we need edit php.ini with above changes? because not working in both cases-thanks

    ReplyDelete
  19. hi admin
    i cant send or receive any emails with amazon ses
    plz help me

    ReplyDelete
  20. is this technique is slow than using ses library ? please reply if anyone has idea

    ReplyDelete
  21. what is the name of database ?

    ReplyDelete

mailxengine Youtueb channel
Make in India
X