php - 使用我的 Phpmailer 连接到 Webmail 服务器时遇到问题
问题描述
一直在尝试使用 phpmailer 使用以下代码将邮件发送到我从 monovm.com 托管服务提供商购买的商业邮件
<?php
//Import PHPMailer classes into the global namespace
//These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;
require 'src/Exception.php';
require 'src/PHPMailer.php';
require 'src/SMTP.php';
require 'src/POP3.php';
//Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
$mail->isSMTP(); //Send using SMTP
$mail->Host = "smtp.haygoldinternational.com";
$mail->Port = 587; //Set the SMTP server to send through
$mail->SMTPAuth = true; //Enable SMTP authentication
$mail->Username = "office@haygoldinternational.com"; //SMTP username
$mail->Password = "mypassword"; //SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; //Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
//TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
if(isset($_POST['btnSubmit']))
{
$mail->setFrom('office@haygoldinternational.com', 'HAYGOLD');
$mail->addAddress('office@haygoldinternational.com', 'HAYGOLD'); //Add a recipient
$mail->addReplyTo("toheebabiodun03@gmail.com", "Abiodun");
//Content
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = "TESTING";
$mail->Body = "Just testing";
$mail->send();
echo 'Message Sent Successfully';
}
}
catch (Exception $e)
{
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
我不断得到的错误是这个
2021-04-03 15:37:28 SERVER -> CLIENT: 220 us2.outbound.mailhostbox.com ESMTP Postfix
2021-04-03 15:37:28 CLIENT -> SERVER: EHLO haygoldinternational.com
2021-04-03 15:37:28 SERVER -> CLIENT: 250-us2.outbound.mailhostbox.com250-PIPELINING250-SIZE 41648128250-VRFY250-ETRN250-STARTTLS250-AUTH PLAIN LOGIN250-AUTH=PLAIN LOGIN250-ENHANCEDSTATUSCODES250-8BITMIME250 DSN
2021-04-03 15:37:28 CLIENT -> SERVER: STARTTLS
2021-04-03 15:37:28 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
SMTP Error: Could not connect to SMTP host.
2021-04-03 15:37:28 CLIENT -> SERVER: QUIT
2021-04-03 15:37:28 SERVER -> CLIENT:
2021-04-03 15:37:28 SMTP ERROR: QUIT command failed:
SMTP Error: Could not connect to SMTP host.
Message could not be sent. Mailer Error: SMTP Error: Could not connect to SMTP host.
可能是什么原因,我能够使用相同的代码来连接我的 gmail,它工作得很好。请帮助兄弟
解决方案
比我在评论中建议的要简单——您要连接的服务器不是您要求连接的服务器。您要求smtp.haygoldinternational.com
但已连接到us2.outbound.mailhostbox.com
. 这将使证书验证失败,就像它检测到名称不匹配时一样。
更改您的Host
值以匹配它(如果它是预期的),或者找出您被重定向到那里的原因。
推荐阅读
- python - python re.split 与 maxsplit 参数
- python - 使用 OpenCV 获得完整的形状图案
- github - “Package.json - 没有这样的文件或目录”错误检查 GitHub 上的詹金斯管道
- reactjs - 在 React 2020 中收到非布尔属性“已完成”的“假”
- android - 如何修复这些错误?我只是想将我的项目连接到 Firebase,但我遇到了所有这些错误
- python - Python 是否也有一些内置数据集(如 R)来执行测试?
- javascript - 如何动态更改附加的子文本 - JQuery
- list - F#:创建一个包含所有列表头部的列表,在列表中
- schema - BizTalk - 分隔平面文件验证
- python - 如何使用 Azure 进行身份验证以便使用 python 运行数据工厂管道测试?