在我的页面上,我有一个使用 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;
}
}
我想我在 TLS/SSL 方面错误地配置了 PHP Mailer,因为我对此很新手。我的网页使用 TLS 1.3 加密可能是一个权宜之计
青春有我