【问题标题】:PhpMailer can't seem to send mail to OutlookPhpMailer 似乎无法将邮件发送到 Outlook
【发布时间】:2020-04-14 19:40:00
【问题描述】:

我一直在尝试制作一个小型电子邮件功能,以便可以从我的网站向我的 Outlook 发送电子邮件。但是我遇到了一些问题.. 我是否必须更改我的php.ini (xampp) 中的任何内容?用户名和密码应该是我的outlookusn/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

感谢您的帮助!

【问题讨论】:

  • 尝试更改 $mail ->SMTPSecure = 'ssl';到 $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
  • $mail ->SMTPDebug = 0 如果您想调试,这不是一个好的起点 ;-)
  • 发送失败后不回显错误消息也无济于事!查看 PHPMailer 提供的 any 示例以了解如何执行此操作。您的 SMTPSecure 模式和 Port 号码的组合无效 - 请参阅 PHPMailer 故障排除指南了解更多信息。

标签: php phpmailer


【解决方案1】:

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

$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-28
    • 2019-01-19
    • 2023-03-20
    • 2012-05-26
    • 2014-04-28
    • 1970-01-01
    • 2014-04-06
    • 1970-01-01
    相关资源
    最近更新 更多