为什么 SMTP 错误:无法连接到服务器:尝试使用 PhpMailer 发送电子邮件时没有到主机 (65) 的路由



我正在尝试使用PhpMailer向用户发送MP3的电子邮件。当我尝试向用户发送电子邮件时,我收到一条消息,指出:SMTP 错误:无法连接到服务器:没有到主机的路由 (65(。我已经读过这可能是gmail不同意其他服务器的结果,但我没有看到任何补救措施。我从 tls 切换到 ssl,这没有帮助。我还尝试了 3 个不同的物理位置,问题仍然存在。这最初工作正常,也许有些东西关闭了,但我不知道是什么。更新我仅在我的托管网站上遇到此问题。本地主机现在正在工作。我的共享服务器上是否缺少一些必要的配置?任何想法将不胜感激。

<?php
session_start();
use PHPMailerPHPMailerPHPMailer;
use PHPMailerPHPMailerException;
date_default_timezone_set('America/New_York');
require_once 'vendor/autoload.php';
$m = new PHPMailer(true);

try{
$m->SMTPDebug = 2;
$m->isSMTP();
$m->Host = 'smtp.gmail.com';
$m->SMTPAuth = true;

$m->Username = 'munsonatl@gmail.com';
$m->Password = 'somethingsecret';

$m->SMTPSecure = 'ssl';
$m->Port = 465;
$m->setFrom('munsonatl@gmail.com', 'Mailer');
$m->addAddress('munsonatl@gmail.com', 'Matt Macy');
$m->addReplyto('reply@mattmacy.com', 'replyAddress');

require 'connect.php';
$itemNum = $_SESSION['itemNum'];

$query2 = "SELECT* FROM MP3s_For_Sale WHERE itemNum = :itemNum";
$LastProduct = $db->prepare($query2);
$LastProduct->bindvalue(':itemNum', $itemNum);
$LastProduct->execute();
$rows = $LastProduct->fetch();
$filename = $rows['path'];
$filesize = $rows['filesize'];
$string =  $rows['wholeMP3'];
$encoding = 'base64';
$type = $rows['type']; 
$m->AddStringAttachment($string,$filename,$encoding,$type);
$m->isHTML(true);
$m->Subject = "Here is an Email";
$m->Body = "<p>This is the body of the email</p><br><strong>Test for 
HTML formatting</strong><br>";
$m->AltBody = "This is the body of an email";
$m->send();
echo "message has been sent";
unset($_SESSION['itemNum']);
} catch (Exception $e){
echo "message could not be sent", $m->ErrorInfo;
}
?>
我没有

像其他人那样发表评论的声誉,但我之前遇到过这个问题,原因是端口在共享主机上被阻止。如果你需要检查你的端口是否被阻止,那么看看 PHP 检查端口是否是 Active

在与我的托管公司第三次交谈后,他们说 web.com 不需要使用端口甚至SMTP来与PhpMailer一起工作。我注释掉了与端口或SMTP有关的所有内容,因此它现在可以工作了。我根本无法向我的辅助电子邮件帐户发送电子邮件,并且它只能在大多数情况下使用我的Gmail帐户。如果有人能告诉我关于 web.com 和正在发生的事情的任何其他信息,那将非常有帮助。

最新更新