PHPMailer:如何从Outlook电子邮件发送电子邮件?

PHPMailer: How can I send an email from an Outlook email?

提问人:MalcolmInTheCenter 提问时间:7/15/2023 更新时间:7/15/2023 访问量:185

问:

我正在使用 PHPMailer 通过我的 Outlook 电子邮件发送电子邮件,但我一直收到此错误

Message could not be sent. Mailer Error:
"The following From address failed: [email protected] : 
MAIL FROM command failed,Client not authenticated to send mail. [
xxxxxx.namprd13.prod.outlook.com 2023-07-14T21:47:08.967Z 08DB842E797B0C23]\r\n,530,5.7.57SMTP server error: MAIL FROM command failed Detail: Client not authenticated to send mail. 
[xxxx.namprd13.prod.outlook.com 2023-07-14T21:47:08.967Z 08DB842E797B0C23]\r\n SMTP code: 530 Additional SMTP info: 5.7.57SMTP server error: 
MAIL FROM command failed Detail: Client not authenticated to send mail. 
[xxxxxx.namprd13.prod.outlook.com 2023-07-14T21:47:08.967Z 08DB842E797B0C23]\r\n SMTP code: 530 Additional SMTP info: 5.7.57"

我正在使用沙盒 outlook 电子邮件,这可能是问题所在,但对此表示高度怀疑,因为我能够使用 ms-graph-sdk 发送消息

这是我的代码:

try {
    //Server settings
    $mail->SMTPDebug  = SMTP::DEBUG_SERVER;
    $mail->Host       = 'smtp-mail.outlook.com'; //smtp.office365.com:587
    $mail->Username   = '[email protected]';
    $mail->Password   = 'xxxxxxxxxx';
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
    $mail->Port       = 587;
    $mail->isSMTP();
    //$mail->SMTPAuth   = true;

    //Recipients
    $mail->setFrom('[email protected]', 'Mailer');
    $mail->addAddress('[email protected]');

    //Content
    $mail->isHTML(true);
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    if (! $response = $mail->send()) {
        Log::info('Message could not be sent.');
        Log::info('Mailer Error: ' . json_encode($mail->ErrorInfo));
        exit;
    } else {
        echo 'Message of Send email using Outlook SMTP server has been sent';
    }
    echo 'Message has been sent';
}
catch (Exception $e) {
    Log::info("Message could not be sent. Mailer Error:" . json_encode($mail->ErrorInfo));
}

我尝试了这里提供的 3 种解决方案 https://stackoverflow.com/a/68312304/2609521 但它们不起作用。
1. 2.enter image description here

enter image description here

3.
enter image description here

PHP 电子邮件 phpmailer

评论

0赞 hakre 7/15/2023
这不是一个编程问题,而纯粹是您运行的 SMTP 配置。按顺序进行 SMTP 设置,验证它(例如 jetmore.org/john/code/swaks/installation.html),然后根据文档配置 PHPMailer。
0赞 Synchro 7/15/2023
我相当确定您不能再使用常规密码身份验证通过 Outlook 发送;您需要配置XOAUTH2。不幸的是,它很棘手且不可靠(感谢Microsoft),但是有一个PHPMailer的设置指南,以及一些背景讨论
0赞 Tangentially Perpendicular 7/15/2023
问题在这里:“详细信息:客户端未经过身份验证以发送邮件。修复您的身份验证。
2赞 M. Eriksson 7/15/2023
你应该停下来一秒钟,想想你在做什么。您目前正在禁用有助于保护电子邮件服务的安全功能,只是为了能够将 SMTP 与 PHP 一起使用。这是错误的做法。如果它适用于他们的图形 sdk,为什么不改用该方法呢?

答: 暂无答案