如何修复 php 邮件证书

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

我正在尝试使用 PHPMailer 类从我的 godaddy VPS 发送电子邮件,但出现以下错误。

请注意,VPS 与不同的服务提供商合作,而 smtp 电子邮件服务与不同的服务提供商合作。 有点像尝试通过 gmail 发送电子邮件,但我使用的是不同的电子邮件 smtp 服务提供商,而不是 gmail。

如果我注释掉 mail->isSMTP 行,那么邮件就会发送,但它会通过我自己服务器的 sendmail 程序发送,而不是通过 smtp。那不是我想要的。

SMTP response is this:
2023-03-31 02:18:42 SERVER -> CLIENT: 220 TLS go ahead
SMTP Error: Could not connect to SMTP host. Connection failed. stream_socket_enable_crypto(): Peer certificate CN=`ns1.tbrjar.com' did not match expected CN=`smtp.tbrjar.com'

//My code is this:
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

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

$mail = new PHPMailer;
$mail->isSMTP(); 
$mail->SMTPDebug = 2; // 0 = off (for production use) - 1 = client messages - 2 = client and server messages
$mail->Host = "smtp.tbrjar.com"; // use $mail->Host = gethostbyname('smtp.gmail.com'); // if your network does not support SMTP over IPv6
$mail->Port = 587; // TLS only
$mail->SMTPSecure = 'tls'; // ssl is depracated
$mail->SMTPAuth = true;
$mail->Username = $smtpUser;
$mail->Password = $smtpPass;
$mail->setFrom($emailFrom, $emailFromName);
$mail->addAddress($emailTo, $emailToName);
$mail->Subject = 'PHPMailer GMail SMTP test';
$mail->msgHTML("test body"); //$mail->msgHTML(file_get_contents('contents.html'), __DIR__); //Read an HTML message body from an external file, convert referenced images to embedded,
$mail->AltBody = 'HTML messaging not supported';
// $mail->addAttachment('images/phpmailer_mini.png'); //Attach an image file

if(!$mail->send()){
    echo "Mailer Error: " . $mail->ErrorInfo;
}else{
    echo "Message sent!";
}
phpmailer
© www.soinside.com 2019 - 2024. All rights reserved.