简体   繁体   English

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

[英]Why SMTP ERROR: Failed to connect to server: No route to host (65) when trying to send email with PhpMailer?

I am attempting to use PhpMailer to send an email of an MP3 to a user.我正在尝试使用 PhpMailer 向用户发送 MP3 电子邮件。 When I try to send an email to the user I get a message saying: SMTP ERROR: Failed to connect to server: No route to host (65) .当我尝试向用户发送电子邮件时,我收到一条消息:SMTP ERROR: Failed to connect to server: No route to host (65) 。 I have read this might be the result of gmail not agreeing with a different server but I don't see any remedy.我读过这可能是 gmail 不同意其他服务器的结果,但我没有看到任何补救措施。 I switched from tls to ssl and that didn't help.我从 tls 切换到 ssl 并没有帮助。 I also tried 3 different physical locations and the problem still persists.我还尝试了 3 个不同的物理位置,但问题仍然存在。 This worked fine initially and maybe something switched off but I don't know what.这最初工作正常,也许有些东西关闭了,但我不知道是什么。 UPDATE I am having this problem only on my hosted site .更新 我仅在我的托管站点上遇到此问题。 localhost is working now.本地主机现在正在工作。 Is there some necessary configuration on my shared server I am missing?我缺少的共享服务器上是否有一些必要的配置? Any ideas would be greatly appreciated.任何想法将不胜感激。

<?php
session_start();
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

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;
}

?>

I don't have the reputation to leave a comment like the others did, but I have had this issue before caused by the port being blocked on shared hosting.我没有像其他人那样发表评论的声誉,但我之前遇到过这个问题,原因是共享主机上的端口被阻止了。 If you need to check if yours is blocked, then look at PHP Checking if a port is Active如果您需要检查您的端口是否被阻止,请查看PHP Checking if a port is Active

After talking with my hosting company for the third time they said web.com does not require the use of ports or even SMTP to work with PhpMailer.在第三次与我的托管公司交谈后,他们说 web.com 不需要使用端口甚至 SMTP 来与 PhpMailer 一起工作。 I commented out everything that has to do with Ports or SMTP and as a result it now works kind of.我注释掉了与端口或 SMTP 相关的所有内容,因此它现在可以正常工作了。 I haven't been able to send email to my secondary email account at all and it works only most of the time with my gmail account.我根本无法向我的辅助电子邮件帐户发送电子邮件,而且它只能在大部分时间与我的 Gmail 帐户一起使用。 If someone can tell me anything else about web.com and what is going on it would be very helpful.如果有人能告诉我有关 web.com 的任何其他信息以及正在发生的事情,那将非常有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM