PHPMailer无法使用ec2发送发送电子邮件 [英] PHPMailer not able to send send email with ec2

查看:118
本文介绍了PHPMailer无法使用ec2发送发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PHPmailer 发送帐户验证邮件,正在使用 AWS ec2 实例,但是,该邮件程序在 localhost上运行正常,但是当我将其上传到服务器电子邮件后, 最初,我使用 SendGrid 凭据发送电子邮件,失败了,然后尝试了 Gmail SMTP ,失败了,在我读到ec2无法发送电子邮件的地方,然后我创建了<另外,strong> SES 仍然无法发送.

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,

本地主机中,可以使用具有相同代码和Gmail凭据的 SendGrid 发送电子邮件,为什么不能与服务器一起发送?

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

我的PHP邮件代码是:

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!

我也有openSSL证书!在ec2的安全组中为入站和出站打开了SMTP端口,一切正常,但 PHPMailer

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

推荐答案

弄清协议.在Host中,您指定tls,但告诉它连接到Port = 465,这不适用于TLS.将Port更改为587(首选),或将加密方法更改为ssl.启用调试输出(SMTPDebug = 2)将使您了解与服务器的对话中发生的情况.

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.

这篇关于PHPMailer无法使用ec2发送发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆