PHPMailer 无法使用 ec2 发送电子邮件

PHPMailer not able to send send email with ec2

我正在使用 PHPmailer 发送帐户验证邮件,我正在使用 AWS ec2 实例,但是,该邮件程序在 localhost 中运行良好,但是当我将其上传到 server 时,电子邮件无法发送, 起初,我使用 SendGrid 凭据发送电子邮件,失败,然后尝试 Gmail SMTP,失败,在某处我读到 ec2 无法发送电子邮件,然后我也创建了 SES,仍然无法发送。

在网上搜索了 abt,但没有解决我的问题的答案,

localhost 中可以使用相同的代码和 Gmail 凭证的 SendGrid 发送电子邮件,为什么我不能发送服务器?

我的 PHP 邮件代码是:

$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';
}

它显示消息已发送但是我收不到邮件,也检查了垃圾邮件文件夹,没有邮件线索!

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

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

仔细阅读 the troubleshooting guide 可能会有帮助。