[英]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.