2016-11-23 158 views
0

我有一个PHPMailer的问题,我想连接到一个配置了我的网站IP的Office 365服务器,这里有一个连接器,因此我可以连接到Office 365 SMTP服务器来进行连接而无需身份验证,因为我的IP地址是列入白名单。如何使用PHPMailer连接到Office 365?

问题是我无法对服务器进行身份验证。

PHPMailer的输出:

2016-11-23 09:06:50 CLIENT -> SERVER: EHLO www.thuis*******.nl 2016-11-23 09:06:50 SMTP Error: Could not authenticate. 2016-11-23 09:06:50 CLIENT -> SERVER: QUIT 2016-11-23 09:06:50 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting 

PHP文件:

$mail = new PHPMailer(); 
$mail->IsSMTP(); 
$mail->SMTPDebug = 1; 
$mail->SMTPAuth = true; 
$mail->SMTPSecure = ''; 
$mail->SMTPAutoTLS = false; 
$mail->Host = "thuis*******-nl.mail.protection.outlook.com"; 
$mail->Port = 25; 
$mail->SetFrom('[email protected]*******.nl', 'John'); 
$mail->AddReplyTo("[email protected]*******.nl"); 
$mail->Subject = "This is the subject"; 
$mail->MsgHTML('Message body'); 
$address = "[email protected]"; 
$mail->AddAddress($address); 
if(!$mail->Send()) { 
    echo "Mailer Error: " . $mail->ErrorInfo; 
} else { 
    echo "Message sent!"; 
} 
+0

您已经将您的代码基于一个过时的示例,因此请确保您使用的是最新版本。如果您阅读错误消息指出的文档,它也会有所帮助。 – Synchro

+0

@Synchro谢谢你,我找到了解决方案,你可以在下面阅读。 –

回答

0

设置SMTPAuthfalse

$mail->SMTPAuth = false; 

原因:我的服务器没有配置任何电子邮件帐户。

将服务器IP地址列入白名单,以便使用@thuis*******.nl从任何邮件地址发送邮件。