dongzhao8233 2018-02-28 20:24
浏览 125
已采纳

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

I am attempting to use PhpMailer to send an email of an MP3 to a user. 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) . I have read this might be the result of gmail not agreeing with a different server but I don't see any remedy. I switched from tls to ssl and that didn't help. I also tried 3 different physical locations and the problem still persists. 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;
}

?>
  • 写回答

2条回答 默认 最新

  • douzhiba6873 2018-03-12 23:02
    关注

    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. I commented out everything that has to do with Ports or SMTP and as a result it now works kind of. 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. If someone can tell me anything else about web.com and what is going on it would be very helpful.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集