PHP Mailer-454 TLS连接失败

问题描述 投票:0回答:1

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

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加密可能是权宜之计]

php email ssl phpmailer
1个回答
1
投票

这里有个提示,如果可行,请不要忘记投票以加强。我们去设置...

$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;
© www.soinside.com 2019 - 2024. All rights reserved.