dongyu2764 2015-08-04 20:06
浏览 44

SMTP错误 - 无法连接到网络

I've been trying to implement SMTP with PHPMailer for about a week now. I'm revising my old mail() php script and am having difficulty even setting up a live test taken right from the example since I keep receiving the same error. I'm currently running a HostGator dedicated server and my MX record (mail server) is through Office 365/Outlook. For some reason, I keep getting the can't connect to network error as seen in the image below.

enter image description here

My code is below which I took from the github SMTP example. I originally used port 587 with 'tls' authentication but this did not work and after speaking with Microsoft they suggested I do port 25 with no authentication. Still the same error. Can anyone explain to me what i'm doing wrong or suggest a better route of approach? Thanks!

Code:

 <?
 require(dirname(__FILE__)."/PHPMailerAutoload.php");
 $mail = new PHPMailer;
 $mail->isSMTP();
 $mail->SMTPDebug = 2;
 $mail->Debugoutput = 'html';
 $mail->Host = 'smtp.office365.com';
 $mail->Port = 25;
 $mail->SMTPSecure = 'tls';
 $mail->SMTPAuth = true;
 $mail->Username = "jason@***.com";
 $mail->Password = "***";
 $mail->setFrom('jason@***.com', 'Jason');
 $mail->addReplyTo('jason@***.com', 'Jason');
 $mail->addAddress('jason@***.com', 'Jason');
 $mail->Subject = 'PHPMailer GMail SMTP test';
 $mail->msgHTML($email_message);
 $mail->AltBody = 'This is a plain-text message body';
 if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
 } else {
echo "Message sent!";
 }
 ?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Jenkins+k8s部署slave节点offline
    • ¥15 微信小游戏反编译后,出现找不到分包的情况
    • ¥15 如何实现从tello无人机上获取实时传输的视频流,然后将获取的视频通过yolov5进行检测
    • ¥15 WPF使用Canvas绘制矢量图问题
    • ¥15 用三极管设计一个单管共射放大电路
    • ¥15 孟德尔随机化r语言运行问题
    • ¥15 pyinstaller编译的时候出现No module named 'imp'
    • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
    • ¥15 怎么把多于硬盘空间放到根目录下
    • ¥15 Matlab问题解答有两个问题