Shreyansh Kashyap
Shreyansh Kashyap

Reputation: 45

Send Email using Amazon SES and PHP Mailer from localhost

I am developing a PHP application where I am trying to send an email for testing purposes. I am using PHPMailer and Amazon SES. Currently, I am in development mode so that software isn't online and I am working from localhost (Xampp). The problem is that the email is not being sent despite of my username, password and all the details being correct.

This is the following code that I am using right now.

<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'phpmailer/src/Exception.php';
require 'phpmailer/src/PHPMailer.php';
require 'phpmailer/src/SMTP.php';

$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->Host = 'email-smtp.us-east-1.amazonaws.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->IsHTML(true);
$mail->SMTPAuth = true;
$mail->Username = 'HIDDEN';
$mail->Password = 'HIDDEN';
$mail->setFrom('[email protected]', 'DateApp');
$mail->addAddress('[email protected]', 'Shreyansh');
$mail->Subject = 'This is a subject.';
$mail->Body    = 'This is a test message.';

if($mail->send()){
  echo "Mail sent!";
}else{
  echo "Error";
}

?>

I am always receiving "Error" message as the mail is not being sent. Please if anybody can let me know what the issue is, I will be grateful. Is it because I am on localhost? Or, would I have to configure my php.ini file to send mails? If yes, please let me know the process.

UPDATE

  1. Its not working online as well. I just tried it. You can see here http://www.startdating.in/test.php

  2. I forgot to mention that I did not configure the domain thing in amazon ses account. I only configured email and SMTP services.

CHANGED DEBUG to 1

ERROR MESSAGE FROM LOCALHOST

2019-10-12 18:25:25 CLIENT -> SERVER: EHLO localhost
2019-10-12 18:25:26 CLIENT -> SERVER: STARTTLS
2019-10-12 18:25:27 CLIENT -> SERVER: EHLO localhost
2019-10-12 18:25:27 CLIENT -> SERVER: AUTH LOGIN
2019-10-12 18:25:27 CLIENT -> SERVER: <credentials hidden>
2019-10-12 18:25:27 CLIENT -> SERVER: <credentials hidden>
2019-10-12 18:25:27 CLIENT -> SERVER: MAIL FROM:<[email protected]>
2019-10-12 18:25:28 CLIENT -> SERVER: RCPT TO:<[email protected]>
2019-10-12 18:25:28 CLIENT -> SERVER: DATA
2019-10-12 18:25:28 CLIENT -> SERVER: Date: Sat, 12 Oct 2019 20:25:24 +0200
2019-10-12 18:25:28 CLIENT -> SERVER: To: Shreyansh <[email protected]>
2019-10-12 18:25:28 CLIENT -> SERVER: From: DateApp <[email protected]>
2019-10-12 18:25:28 CLIENT -> SERVER: Subject: This is a subject.
2019-10-12 18:25:28 CLIENT -> SERVER: Message-ID: <wOLtFTSGmh2slZxkUcYhUA4lc0sTi0UdiiDHjUzbGs@localhost>
2019-10-12 18:25:28 CLIENT -> SERVER: X-Mailer: PHPMailer 6.0.6 (https://github.com/PHPMailer/PHPMailer)
2019-10-12 18:25:28 CLIENT -> SERVER: MIME-Version: 1.0
2019-10-12 18:25:28 CLIENT -> SERVER: Content-Type: text/html; charset=iso-8859-1
2019-10-12 18:25:28 CLIENT -> SERVER:
2019-10-12 18:25:28 CLIENT -> SERVER: This is a test message.
2019-10-12 18:25:28 CLIENT -> SERVER:
2019-10-12 18:25:28 CLIENT -> SERVER: .
2019-10-12 18:25:29 SMTP ERROR: DATA END command failed: 554 Message rejected: Email address is not verified. The following identities failed the check in region US-EAST-1: [email protected]
SMTP Error: data not accepted.
Error2019-10-12 18:25:29 CLIENT -> SERVER: QUIT

ERROR MESSAGE FROM www.stardating.in/test.php

2019-10-12 18:25:53 SMTP ERROR: Failed to connect to server: Connection refused (111)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Error

Also, I have configured and verified stardating.in domain name in the amazon ses account. Still the problem persists.

Upvotes: 1

Views: 3034

Answers (1)

qkhanhpro
qkhanhpro

Reputation: 5220

You see

SMTP ERROR: DATA END command failed: 554 Message rejected: Email address is not verified. The following identities failed the check in region US-EAST-1: [email protected] SMTP Error: data not accepted.

AWS SES "Sandbox mode" allow you to only send email from and to verified email addresses. Full restriction list here:

You can only send mail to verified email addresses and domains, or to the Amazon SES mailbox simulator.

You can only send mail from verified email addresses and domains.

Note

This restriction applies even when your account isn't in the sandbox.

You can send a maximum of 200 messages per 24-hour period.

You can send a maximum of 1 message per second.

To get out of "Sandbox mode", send them a ticket

https://docs.aws.amazon.com/ses/latest/DeveloperGuide/request-production-access.html

Upvotes: 2

Related Questions