PHPMailer not able to send send email with ec2

雨燕双飞 提交于 2019-12-12 00:57:50

问题


I'm using PHPmailer to send account verification mail, I'm using AWS ec2 instance, however, that mailer is working fine in localhost but when I upload that to server emails are not going, at first, i used SendGrid credentials to send emails, failed, then tried Gmail SMTP, failed, and somewhere I read that ec2 can't send emails, then I created SES also, still can't able to send.

searched on the web abt that but no answers are fixing my problem,

in localhost, in can send emails with the same code and with SendGrid of Gmail credentials, why I can't send with the server?

my PHP mailer code is:

$sub = "Thankyou For registration! Confirm Your mail to Login";
$mailBody = "<h1>You are successfully registered<br />Visit site to login</h1>";

require 'mailer/PHPMailerAutoload.php';

$mail = new PHPMailer;

$mail->isSMTP();                                   // Set mailer to use SMTP
$mail->Host = "tls://email-smtp.us-east-1.amazonaws.com";                    // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                            // Enable SMTP authentication
$mail->Username = "smtp_username";          // SMTP username
$mail->Password = "smtp_password"; // SMTP password
// $mail->SMTPSecure = 'ssl';                         // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465;                                 // TCP port to connect to

$mail->setFrom("my_mail_id@gmail.com", "SMTP_REPLAY_NAME");
$mail->addReplyTo("my_mail_id@gmail.com", "SMTP_REPLAY_NAME");
$mail->addAddress("recipient_mail_id@gmail.com");   // Add a recipient

$mail->isHTML(true);  // Set email format to HTML
$mail->Subject = $sub;
$mail->Body    = $mailBody;
if(!$mail->send()) {
echo 'Message could not be sent.';
} else {
echo 'Message has been sent';
}

it shows Message has been sent but I cant receive emails, checked in spam folder also, no clue of mail!

even I have openSSL certificate also! opened SMTP port for both inbound and outbound in security group of ec2, everything working fine but PHPMailer!


回答1:


Get your protocols straight. In the Host you're specifying tls, but telling it to connect to Port = 465, which will not work with TLS. Either change your Port to 587 (preferred) or change your encryption method to ssl. Enabling debug output (SMTPDebug = 2) will let you in on what's happening in the conversation with the server.

A perusal of the troubleshooting guide would probably help.



来源:https://stackoverflow.com/questions/42517812/phpmailer-not-able-to-send-send-email-with-ec2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!