dongzhao8233 2018-02-28 20:24
浏览 125


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.

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;


require_once 'vendor/autoload.php';

$m = new PHPMailer(true);

$m->SMTPDebug = 2;
$m->Host = '';
$m->SMTPAuth = true;

$m->Username = '';
$m->Password = 'somethingsecret';

$m->SMTPSecure = 'ssl';
$m->Port = 465;

$m->setFrom('', 'Mailer');
$m->addAddress('', 'Matt Macy');
$m->addReplyto('', 'replyAddress');

require 'connect.php';

$itemNum = $_SESSION['itemNum'];

$query2 = "SELECT* FROM MP3s_For_Sale WHERE itemNum = :itemNum";
$LastProduct = $db->prepare($query2);
$LastProduct->bindvalue(':itemNum', $itemNum);

$rows = $LastProduct->fetch();

$filename = $rows['path'];
$filesize = $rows['filesize'];
$string =  $rows['wholeMP3'];
$encoding = 'base64';
$type = $rows['type']; 



$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";
echo "message has been sent";


} 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 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 and what is going on it would be very helpful.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥66 定制开发肯德基自动化网站下单软件
  • ¥20 vscode虚拟环境依赖包未安装
  • ¥15 odoo17关于owl开发js代码问题
  • ¥15 光纤中多普勒频移公式的推导
  • ¥15 怎么制作一个人脸识别门禁系统
  • ¥20 大华dss监控平台网络关闭登不进去
  • ¥15 请使用蚁群算法解决下列问题,并给出我完整的代码
  • ¥20 关于php录入完成后,批量更新数据库
  • ¥15 请教往复密封润滑问题
  • ¥15 cocos creator发布ios包