Godaddy - Office365 SMTP不起作用?

时间:2016-12-04 16:29:32

标签: php email smtp office365

我使用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

什么似乎是一个问题?我在网上查了很多帖子,但似乎没什么用。任何想法??

1 个答案:

答案 0 :(得分:0)

经济托管smtp上的

将无效,请按照下面列出的邮件驱动程序解决方案

    MAIL_DRIVER=mail
    MAIL_HOST=smtp.office365.com
    MAIL_PORT=587
    MAIL_USERNAME=office365_email
    MAIL_PASSWORD=office365_password
    MAIL_FORM=office365_email
    MAIL_ENCRYPTION=tls

邮件可能需要大约2-5分钟才能完成,但它是可行的解决方案。 感谢