I want to send mail through php mail on Amazon SES service, In using PHP Mail But I am not able to send send. I already verify the my email_id. I am using this tutorial as reference http://www.codeproject.com/Articles/786596/How-to-Use-Amazon-SES-to-Send-Email-from-PHP. But It is not sending mail from Amazon SES services, please tell me where I am wrong ? Previously I was using the same id to send mails from localserver XAMPP. It was working.
sendMail.php
<?php >
function Send_Mail($to,$subject,$body)
{
require 'class.phpmailer.php';
$from = "Senders_Email_Address";
$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 = "Senders_Email_Address"; // SMTP Username
$mail->Password = "MyPassword"; // SMTP Password
$mail->SetFrom($from, 'From Name');
$mail->AddReplyTo($from,'Senders_Email_Address');
$mail->Subject = $subject;
$mail->MsgHTML($body);
$address = $to;
$mail->AddAddress($address, $to);
if(!$mail->Send())
return false;
else
return true;
}
?>
index.php
<html>
<body>
<h1>Welcome to my home page!</h1>
<p>Some text.</p>
<p>Some more text.</p>
<?php
require 'sendMail.php';
$to = "Senders_Email_Address";
$subject = "Test Mail Subject";
$body = "Hi<br/>Test Mail<br/>Amazon SES"; // HTML tags
Send_Mail($to,$subject,$body);
?>
</body>
</html>
sendMail.php, class.phpmailer.php, class.smtp.php and index.php are in the same directory.
$host = ' email-smtp.us-west-2.amazonaws.com '; $port = 587; // The subject line of the email $subject = 'Amazon SES test (SMTP interface accessed using PHP)'; // The plain-text body of the email $bodyText = "Email Test\r\nThis email was sent through the Amazon SES SMTP interface using the PHPMailer class."; // The ...
With Amazon SES, you can send an email in three ways: using the console, using the Simple Mail Transfer Protocol (SMTP) interface, or using the API.
PHP makes use of mail() function to send an email. This function requires three mandatory arguments that specify the recipient's email address, the subject of the the message and the actual message additionally there are other two optional parameters. mail( to, subject, message, headers, parameters );
You can send an email with Amazon Simple Email Service (Amazon SES) using the Amazon SES console, the Amazon SES Simple Mail Transfer Protocol (SMTP) interface, or the Amazon SES API. You typically use the console to send test emails and manage your sending activity.
Neelabh, you are missing something. try following:
<?php >
function Send_Mail($to,$subject,$body)
{
require 'class.phpmailer.php';
$from = "verified_email address";
$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 = "Your_SMTP_Username
"; // SMTP Username
$mail->Password = "SMTP_Password"; // SMTP Password
$mail->SetFrom($from, 'From Name');
$mail->AddReplyTo($from,'yourdomain.com or verified email address');
$mail->Subject = $subject;
$mail->MsgHTML($body);
$address = $to;
$mail->AddAddress($address, $to);
if(!$mail->Send())
return false;
else
return true;
}
?>
Also, create an index file like below:
<?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);
?>
Please note that if you have only sandbox access of SES, then the recipient email address also needs to be verified. or you could verify your domain. let me know if this works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With