我正在使用outlook.com的SMTP服务器尝试PHPMailer但我一直收到SMTP错误 我按照PHPMailer的github页面中的示例代码进行了操作,并且我也查看了有关SO的其他问题,但那里的答案并没有解决我的问题
这是代码
Outlet
这是调试输出
<?php
date_default_timezone_set('Etc/UTC');
require_once 'vendor/autoload.php';
$mail = new PHPMailer;
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
//Tell PHPMailer to use SMTP
$mail->isSMTP();
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp-mail.outlook.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication
$mail->Username = "user@outlook.com";
//Password to use for SMTP authentication
$mail->Password = "pass";
//Set who the message is to be sent from
$mail->setFrom('user@outlook.com', 'User');
//Set who the message is to be sent to
$mail->addAddress('recipient@gmail.com', 'Recipient');
//Set the subject line
$mail->Subject = 'PHPMailer SMTP test';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//send the message, check for errors
if (!$mail->send()) {
echo "<br><br>Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
答案 0 :(得分:0)
在阅读了Synchro的评论后,我尝试首先从网上登录到Outlook,它给了我一个验证码来解决。
之后我再次尝试运行脚本,它运行正常,所以我猜是outlook的bot预防系统阻止了脚本。
答案 1 :(得分:-1)
也许我错了,但据我所知,你正在使用属性“Body”来尝试发送HTML数据,但在PHPmailer中有一个MsgHTML属性。可能是这是问题(如上所述可能不是,但值得测试)。
替换你的行:
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
由:
$mail->MsgHTML('This is the HTML message body <b>in bold!</b>');
并测试;)
好看,
好吧,似乎上面没有任何补充。我已经在一个全新的yahoo.com邮件帐户中测试了你的代码,它运行得很好。我只更改了我的个人帐户数据和要求行:
<?php
date_default_timezone_set('Etc/UTC');
require_once 'include/PHPMaile/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
//Tell PHPMailer to use SMTP
$mail->isSMTP();
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.mail.yahoo.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication
$mail->Username = "xxx@yahoo.com";
//Password to use for SMTP authentication
$mail->Password = "xxx";
//Set who the message is to be sent from
$mail->setFrom('xxx@yahoo.com', 'User');
//Set who the message is to be sent to
$mail->addAddress('xxx@xxx.com', 'Recipient');
//Set the subject line
$mail->Subject = 'PHPMailer SMTP test';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//send the message, check for errors
if (!$mail->send()) {
echo "<br><br>Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
希望这有帮助。