如何解决AWS SES 电子邮件发送错误:无法连接到 SMTP 主机
由于我在 AWS 上的账户在沙箱中,所以我在 aws 中创建了两个电子邮件地址并对其进行了验证。然后我创建了 SMTP 凭据。我已经在我的 PHP 邮件程序函数中使用了凭据,但它一直说无法连接到 SMTP 主机。不知道我在这里做错了什么。这里还有一件事是,如果我使用 Cpanel 或任何其他 SMTP 设置而不是 aws,那么此脚本可以工作,这意味着脚本没有任何问题。
function sendMail($data){
$mail = new PHPMailer(true);
try {
//Server settings
// $mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = MAIL_HOST; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = MAIL_USERNAME; // SMTP username
$mail->Password = MAIL_PASSWORD; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
$mail->setFrom(MAIL_FROM,MAIL_NAME);
$mail->addAddress($data['to'],$data['name']);
$mail->addReplyTo(MAIL_REPLYTO);
// $mail->addCC('cc@example.com');
//$mail->addBCC('bcc@example.com');
$mail->isHTML(true);
$mail->Subject = $data['subject'];
$mail->Body = $data['message'];
//$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
$array['code'] = 200;
$array['msg'] = "success";
return $array;
} catch (Exception $e) {
$array['code'] = 201;
$array['msg'] = $mail->ErrorInfo;
return $array;
}
}
错误:
We do not authorize the use of this system to transport unsolicited,220 and/or bulk e-mail.
<br>
2021-02-19 08:55:59 CLIENT -> SERVER: EHLO domain.com
<br>
2021-02-19 08:55:59 SERVER -> CLIENT: 250-ip-172.xx.xx.xxx.sysadmin.info Hello domain.com [172.xx.xx.xxx]250-SIZE 52428800250-8BITMIME250-PIPELINING250-AUTH PLAIN LOGIN250-STARTTLS250 HELP
<br>
2021-02-19 08:55:59 CLIENT -> SERVER: STARTTLS
<br>
2021-02-19 08:55:59 SERVER -> CLIENT: 220 TLS go ahead
<br>
SMTP Error: Could not connect to SMTP host.
<br>
2021-02-19 08:55:59 CLIENT -> SERVER: QUIT
<br>
2021-02-19 08:55:59
<br>
2021-02-19 08:55:59
<br>
在终端上,我也这样做以检查端口是否打开
Nmap -p587 IP
结果:
Host is up (0.00036s latency).
PORT STATE SERVICE
587/tcp open submission
如果我把这个命令
telnet email-smtp.us-east-1.amazonaws.com 587
telnet email-smtp.us-east-1.amazonaws.com 25
它说
220-We do not authorize the use of this system to transport unsolicited,220 and/or bulk e-mail.
不知道为什么我无法从脚本向我经过验证的电子邮件地址发送电子邮件。请帮忙
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。