繁体   English   中英

PHP 邮件程序 - 454 TLS 连接失败

[英]PHP Mailer - 454 TLS connection failed

在我的页面上,我有一个使用 PHP Mailer 的联系表。 一开始,仅出于测试目的,我将它与我的 Gmail 帐户一起使用。 一切都像一个魅力。 然后我决定将电子邮件服务从 Gmail 更改为来自我的托管服务提供商的电子邮件服务。 然后问题就开始了。 每次我尝试发送 email 时,都会发生异常:

2020-05-13 20:53:44 CLIENT -> SERVER: STARTTLS
2020-05-13 20:53:44 SERVER -> CLIENT: 220 ready for tls
SMTP Error: Could not connect to SMTP host.
2020-05-13 20:53:44 CLIENT -> SERVER: QUIT
2020-05-13 20:53:44 SERVER -> CLIENT: 454 TLS connection failed: error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure (#4.3.0)
2020-05-13 20:53:44 SMTP ERROR: QUIT command failed: 454 TLS connection failed: error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure (#4.3.0)

这是我发送电子邮件的代码:

<?php

    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\Exception;
    use PHPMailer\PHPMailer\SMTP;

    require 'PHPMailer.php';
    require 'SMTP.php';
    require 'Exception.php';

    class Mailer
    {
        private $mail;

        public function __construct($host, $user, $password, $port = 587)
        {
            $this->mail = new PHPMailer();
            try
            {
                $this->mail->SMTPDebug = SMTP::DEBUG_SERVER;  
                $this->mail->CharSet    = "UTF-8";
                $this->mail->isSMTP();
                $this->mail->Host       = $host;
                $this->mail->SMTPAuth   = true;
                $this->mail->SMTPSecure = 'ssl';
                $this->mail->Username   = $user;
                $this->mail->Password   = $password;
                $this->mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
                $this->mail->Port       = $port;
            }
            catch(Exception $e)
            {
                echo "Exception: " . $e;
            }
        }

        public function Send($from, $alias, $to, $subject, $body, $cc)
        {
            try
            {
                $this->mail->setFrom($from, $alias);
                $this->mail->addAddress($to);

                $this->mail->isHTML(true);
                $this->mail->Subject = $subject;
                $this->mail->Body    = $body;

                if($cc !== '')
                {
                    $this->mail->AddCC($cc);
                }

                if(!$this->mail->send())
                {
                    die($this->mail->ErrorInfo);
                }

                return true;
            }
            catch (Exception $e)
            {
                return false;
            }
        }

我想我在 TLS/SSL 方面错误地配置了 PHP Mailer,因为我对此很陌生。 我的网页使用 TLS 1.3 加密可能是一个方便的信息

这里有一个提示,如果它有效,不要忘记投票加强。 让我们 go 到设置...

$mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => false
    )
);

请记住,这是一种可以立即发挥作用的姑息性解决方案,但我建议调查该问题。 另一个细节是使用端口 465 和 587 进行测试,有时可能是这样!

$mail->Port = "587";
$mail->SMTPSecure = "tls";

另一件事我不明白...为什么我要使用$ this->mail->SMTPSecure两次?

 $this->mail->SMTPSecure = 'ssl';
 $this->mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM