AWS SES 电子邮件发送错误:无法连接到 SMTP 主机

问题描述

由于我在 AWS 上的账户在沙箱中,所以我在 aws 中创建了两个电子邮件地址并对其进行了验证。然后我创建了 SMTP 凭据。我已经在我的 PHP 邮件程序函数中使用了凭据,但它一直说无法连接到 SMTP 主机。不知道我在这里做错了什么。这里还有一件事是,如果我使用 Cpanel 或任何其他 SMTP 设置而不是 aws,那么此脚本可以工作,这意味着脚本没有任何问题。

PHPmailer 功能

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 -&gt; SERVER: EHLO domain.com
    <br>
2021-02-19 08:55:59 SERVER -&gt; 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 -&gt; SERVER: STARTTLS
            <br>
2021-02-19 08:55:59 SERVER -&gt; CLIENT: 220 TLS go ahead
                <br>
SMTP Error: Could not connect to SMTP host.
                    <br>
2021-02-19 08:55:59 CLIENT -&gt; 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 (将#修改为@)