使用php发送Office 365电子邮件时出错

时间:2016-09-12 10:44:10

标签: php office365 phpmailer

我想将邮件作为Outlook邮件发送...但如果某些端口号被更改,它会显示连接错误和身份验证错误...我的代码有什么问题....

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->CharSet = 'UTF-8';
$mail->SMTPAuth   = true; 
$mail->SMTPSecure = "ssl";
$mail->Host       = "outlook.office365.com";
$mail->Port       = 993;
$mail->Username = "harish.reddy@skoopview.com";   
$mail->Password = "XXXXXXX";
$mail->From = $from;
$mail->FromName= $FromName;
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $message;
$mail->addAddress('harish.reddy@skoopview.com','harish');
if(!$mail->send()){
 echo "Mailer Error: " . $mail->ErrorInfo;
}else{
 echo "E-Mail has been sent";
}

它显示这样的错误......我做什么??

  

服务器 - >客户端:*确定Microsoft Exchange IMAP4服务已准备就绪。   [SABLAE4AUABSADAANgBDAEEAMAAwADUAMwAuAGEAcABjAHAAcgBkADAANgAuAHAAcgBvAGQALgBvAHUAdABsAG8AbwBrAC4AYwBvAG0A]   * BYE连接已关闭。 13 2016-09-12 10:50:13 SMTP注意:检查是否已连接EOF 2016-09-12 10:50:13 SMTP错误:   无法进行身份验证。 2016-09-12 10:50:13 SMTP connect()失败。   https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting梅勒   错误:SMTP连接()失败。   https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

...三江源,

2 个答案:

答案 0 :(得分:1)

如George所述,端口应为587。请确保您使用的是TLS:

$mail->Port = 587;  
$mail->SMTPSecure = 'tls';
$mail->Host = 'smtp-mail.outlook.com;smtp.office365.com';  // Specify main and backup SMTP servers

但是Outlook自签名了自己的SSL / TLS证书。因此,您需要按照https://github.com/PHPMailer/PHPMailer/issues/914添加以下代码:

$mail->SMTPOptions = array(
                'ssl' => array(
                    'verify_peer' => false,
                    'verify_peer_name' => false,
                    'allow_self_signed' => true
                )
            );

答案 1 :(得分:0)