【发布时间】: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 故障排除指南了解更多信息。