【发布时间】:2017-04-26 15:13:39
【问题描述】:
我正在使用 PHPMailer 并尝试过其他方法,但这根本行不通。我不断收到服务器一直拒绝我访问的错误。这是使用的示例代码:
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.office365.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'xx@xx.com'; // SMTP username
$mail->Password = 'xxx'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('from@example.com', 'Mailer');
$mail->addAddress('joe@example.net', 'Joe User'); // Add a recipient
$mail->addReplyTo('info@example.com', 'Information');
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
我使用的设置与官方文档中显示的相同:https://support.office.com/en-gb/article/POP-and-IMAP-settings-for-Outlook-Office-365-for-business-7fc677eb-2491-4cbc-8153-8e7113525f6c
似乎有什么问题?我在网上查了很多帖子,但似乎没有任何效果。有什么想法吗?
【问题讨论】:
-
发帖前先搜索。这是一个众所周知的问题,在 PHPMailer 文档和这里的无数问题中都有介绍:GoDaddy 阻止出站 SMTP,除非通过他们自己的服务器。
-
当然我事先搜索过。即使使用他们自己的服务器,似乎也没有任何效果。您是否有上述 php 的示例代码可以运行并自己测试过?
-
这与您的 Office365 设置无关。问题出在 GoDaddy。我建议你read their docs。需要明确的是,您发布的代码在不阻止出站 SMTP 的 ISP 上可以正常工作。
标签: php email smtp office365 phpmailer