首页 文章

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

提问于
浏览
0

我正在使用 PHPmailer 发送帐户验证邮件,我正在使用 AWS ec2 实例,但是,该邮件程序在 localhost 正常工作但是当我上传到 server 时,电子邮件不会发送,起初,我使用 SendGrid 凭据发送电子邮件,失败了,然后试了 Gmail SMTP ,失败了,在某处我读到ec2无法发送电子邮件,然后我也创建了 SES ,仍然无法发送 .

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

localhost 中,可以发送具有相同代码和 SendGrid 的Gmail凭据的电子邮件,为什么我无法与服务器一起发送?

我的PHP邮件代码是:

$sub = "Thankyou For registration! Confirm Your mail to Login";
$mailBody = "<h1>You are successfully registered
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'; }

它显示 Message has been sent 但我无法收到电子邮件,也检查了 spam 文件夹,没有邮件的线索!

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

1 回答

  • 1

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

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

相关问题