PhpMailer似乎无法将邮件发送到Outlook

时间:2019-12-23 14:01:50

标签: php phpmailer

我一直在尝试创建一个小的电子邮件功能,因此可以从我的网站向Outlook发送电子邮件。但是我遇到了一些问题。 我是否需要更改php.ini(xampp)中的任何内容?用户名和密码应该是我的看法usn/pass,对吗? 当我运行此.php时,它说:echo "Mail Not Sent"; 真的看不到我在做什么错。

   require 'PHPMailer-master/PHPMailerAutoload.php';
   $mail = new PHPMailer();
   $mail ->IsSmtp();
   $mail ->SMTPDebug = 0;
   $mail ->SMTPAuth = true;
   $mail ->SMTPSecure = 'ssl';
   $mail ->Host = "smtp.office365.com";
   $mail ->Port = 587; // or 587
   $mail ->IsHTML(true);
   $mail ->Username = "mhoegstrup@company.com";
   $mail ->Password = "XXXX";
   $mail ->SetFrom("mhoegstrup@company.com");
   $mail ->Subject = "Test";
   $mail ->Body = "HEJJ";
   $mail ->AddAddress("mhoegstrup@company.com");
   if(!$mail->Send())
   {
       echo "Mail Not Sent";
   }
   else
   {
       echo "Mail Sent";
   }

PHPMailer文件来自:https://drive.google.com/file/d/0BzlVPBUP5IM8dmpDZ2tEZjdRaEU/view

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

我检查了Outlook服务的文档和设置: 我意识到您只需要将SMTPSecure设置为PHPMailer::ENCRYPTION_STARTTLS

$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;