PHP Mailer 返回 PHP 致命错误:未捕获 PHPMailer\PHPMailer\Exception:SMTP 错误:无法进行身份验证

2024-04-20

我看到了很多类似的问题,比如我的问题,但从来没有一个对我有帮助的。我正在尝试 PHPMailerhttps://github.com/PHPMailer/PHPMailer https://github.com/PHPMailer/PHPMailer。我正在使用 xampp 服务器对其进行测试,一切正常。但是当我在我的页面上上传整个 phpMailer 时,出现了一些问题。在我的日志文件中,我仍然收到此错误:

PHP 致命错误:未捕获 PHPMailer\PHPMailer\Exception:SMTP 错误:无法进行身份验证。在/web/test/vendor/phpmailer/phpmailer/src/PHPMailer.php:2089 堆栈跟踪: #0 web/test/vendor/phpmailer/phpmailer/src/PHPMailer.php(1900): PHPMailer\PHPMailer\PHPMailer->smtpConnect() #1 web/test/vendor/phpmailer/phpmailer/src/PHPMailer.php(1614): PHPMailer\PHPMailer\PHPMailer->smtpSend() #2 web/test/vendor/phpmailer/phpmailer/src/PHPMailer.php(1447): PHPMailer\PHPMailer\PHPMailer->postSend() #3 web/test/idk.php(31): PHPMailer\PHPMailer\PHPMailer->send() #4 {主要} 抛出在 web/test/vendor/phpmailer/phpmailer/src/PHPMailer.php 第 2089 行`

有谁知道,如何解决这个问题?我很确定我的登录凭据没问题。奇怪的是它在 xampp 上工作得很好,但在我的页面上却不行。我使用的是最新的 PHPMailer,并且我没有编辑任何内容,因此您可以在 PHPMailer github 上查看代码。 如果有人需要更多信息,请告诉我。 太感谢了!

编辑:这是我的 idk.php 文件(代码片段不能正常工作,但我认为您可以阅读它):

<?php 
declare( strict_types = 1 );

// Check if the form is submitted
if ( isset( $_POST['submit'] ) ) {
    // retrieve the form data by using the element's name attributes value as key
    
    $subject = $_REQUEST['subject'];
    $body = $_REQUEST['body'];
    $sender = $_REQUEST['sender'];

    require __DIR__ . '/vendor/autoload.php';

    $mailer = new \PHPMailer\PHPMailer\PHPMailer( true );
    //$mailer->SMTPDebug = \PHPMailer\PHPMailer\SMTP::DEBUG_SERVER tento řádek povoluje client -> server a server -> client zprávy

    $mailer->isSMTP();
    $mailer->Host = 'smtp.gmail.com';
    $mailer->SMTPAuth = true;
    $mailer->Username = '[email protected] /cdn-cgi/l/email-protection';
    $mailer->Password = 'myPassword';
    $mailer->SMTPSecure = \PHPMailer\PHPMailer\PHPMailer::ENCRYPTION_STARTTLS;
    $mailer->Port = 587;
    $mailer->setFrom( '[email protected] /cdn-cgi/l/email-protection' );
    $mailer->addReplyTo( '[email protected] /cdn-cgi/l/email-protection' );
    $mailer->addAddress( $sender );
    $mailer->isHTML( true );
    $mailer->Subject = $subject;
    $mailer->Body = $body;
    $mailer->send();
}
?>

也许我应该说我在我的网络托管上使用 .htaccess 文件。我不确定,但这也许就是我收到这些错误的原因。当我尝试访问 idk.php 文件时,我收到 http 错误 500。我做了一些研究,发现这个 500 错误和 htaccess 文件之间存在某种联系。

编辑: 我关闭了不太安全的应用程序,但它仍然不起作用。我将端口更改为 465,现在此文件中的第 2076 行出现错误:https://github.com/PHPMailer/PHPMailer/blob/master/src/PHPMailer.php https://github.com/PHPMailer/PHPMailer/blob/master/src/PHPMailer.php


这是 Gmail 问题,您需要关闭“不太安全的应用程序访问”

更多信息:https://support.google.com/accounts/answer/6010255?hl=en#zippy=%2Cif-less-secure-app-access-is-on-for-your-account%2Cif-less-secure-app -您的帐户的访问权限已关闭 https://support.google.com/accounts/answer/6010255?hl=en#zippy=%2Cif-less-secure-app-access-is-on-for-your-account%2Cif-less-secure-app-access-is-off-for-your-account

关闭“不太安全的应用程序访问”

https://myaccount.google.com/lesssecureapps https://myaccount.google.com/lesssecureapps

示例(PHPMailer v6.2.0)

<?php

/**
 * This example shows settings to use when sending via Google's Gmail servers.
 * This uses traditional id & password authentication - look at the gmail_xoauth.phps
 * example to see how to use XOAUTH2.
 * The IMAP section shows how to save this message to the 'Sent Mail' folder using IMAP commands.
 */

//Import PHPMailer classes into the global namespace
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;

require 'vendor/autoload.php';

//Create a new PHPMailer instance
$mail = new PHPMailer();

//Tell PHPMailer to use SMTP
$mail->isSMTP();

//Enable SMTP debugging
// SMTP::DEBUG_OFF = off (for production use)
// SMTP::DEBUG_CLIENT = client messages
// SMTP::DEBUG_SERVER = client and server messages
$mail->SMTPDebug = SMTP::DEBUG_SERVER;

//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMTP over IPv6

//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;

//Set the encryption mechanism to use - STARTTLS or SMTPS
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;

//Whether to use SMTP authentication
$mail->SMTPAuth = true;

//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = 'CHANGEME';

//Password to use for SMTP authentication
$mail->Password = 'CHANGEME';

//Set who the message is to be sent from
$mail->setFrom('[email protected] /cdn-cgi/l/email-protection', 'First Last');

//Set an alternative reply-to address
$mail->addReplyTo('[email protected] /cdn-cgi/l/email-protection', 'First Last');

//Set who the message is to be sent to
$mail->addAddress('CHANGEME', 'John Doe');

//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test';

$mail->msgHTML('This is a plain-text message body');


//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';

//Attach an image file

//send the message, check for errors
if (!$mail->send()) {
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message sent!';
    //Section 2: IMAP
    //Uncomment these to save your message in the 'Sent Mail' folder.
    #if (save_mail($mail)) {
    #    echo "Message saved!";
    #}
}

取自https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

PHP Mailer 返回 PHP 致命错误:未捕获 PHPMailer\PHPMailer\Exception:SMTP 错误:无法进行身份验证 的相关文章

  • 删除 IE9 边缘周围的 2px 灰色边框

    我正在尝试对这个网站进行编码 尝试关键字 并且我正在尝试找出如何删除这个阴影2px灰色边框延伸到 IE9 窗口的内部 至少顶部 左侧和底部 我的边距设置为零 因此所有页面元素都到达页面的最边缘 但使用 IE9 它们会停在这个灰色边框处 我没
  • JavaScript 中的 Promise 有什么意义?

    一个承诺是一个 可能现在可用 或将来可用 或永远不可用的值 来源 MDN 假设我有一个想要处理图片的应用程序 图片已加载 例如在算法在后台使用它之后 或某种其他类型的延迟 现在我想检查一下图片是否可以在future 通过使用承诺 而不是回调
  • React Router v4 不渲染组件

    React Router v4 渲染组件存在问题 在应用程序初始加载时 它将呈现与 URL 相对应的正确组件 但是 任何后续的组件Link单击不会呈现所需的组件 图书馆 反应路由器 4 2 2 https reacttraining com
  • 如何在另一个自定义 Hook 中使用返回值的自定义 Hook?

    我正在使用 React native 其中有一个名为的自定义 HookuseUser使用以下方法从 AWS Amplify 获取用户信息Auth getUserInfro方法 然后获取返回对象的一部分并用它设置一个状态变量 我还有另一个名为
  • 如何禁用 iPhone 邮件应用程序中的电话号码链接?

    我的公司正在发送数字电子邮件收据 但遇到了 iPhone Mail 检测数字数据并将其自动链接为电话号码的问题 我已经看到元标记应该可以解决 iPhone 上的 Mobil Safari 中的问题 但该技巧似乎不适用于 Mail 有谁知道如
  • 为什么我的交互式图像仅在 Internet Explorer 上出现故障?

    我的问题 我为自己制作了一个图像地图 交互式图像 它在 Chrome safari 和 Firefox 上完美运行 然而 当我在可怕的互联网浏览器上尝试它时 它真的很糟糕 这些小点应该扩展到更大的盒子中 在互联网浏览器上它要么不起作用 要么
  • 如何正确取消引用然后删除 JavaScript 对象?

    我想知道从内存中完全取消引用 JavaScript 对象的正确方法 确保删除时不会在内存中悬空 并且垃圾收集器会删除该对象 当我看这个问题时在 JavaScript 中删除对象 https stackoverflow com questio
  • URL 中的 %2F 中断并且未引用所需的 .php 文件 [重复]

    这个问题在这里已经有答案了 我需要将 作为变量作为 URL 的一部分传递 我的结构如下所示 www domain com listings page 1 city Burnaby South type Townhome bedroom 2
  • 如何在 Zend Framework 3 中注册自定义表单视图助手

    我正在将继承的 Zend Framework 2 应用程序迁移到 Zend Framework 3 并且在注册自定义表单视图助手时遇到了一些困难 这些助手在应用程序使用版本 2 时起作用 主要用于添加标签属性以实现可访问性 例如 这是一个自
  • 用于选择特定 div 中具有特定类的锚元素的 jQuery 选择器是什么

    我有一些这样的代码 我想选择每个 a 带有类的标签status在 div 中foo div a class status a div 你可以这样做 foo find status a
  • 如何从浏览器向服务器发送“页面将关闭”消息?

    我想向每个 html 文档添加一个脚本 JavaScript 该脚本向服务器发送两条消息 页面确实打开了 页面将关闭 此消息包含页面打开的时间 打开消息应在文档加载时 或加载完成时 发送 这是简单的部分 The close message
  • $resource.query 返回分割字符串(字符数组)而不是字符串

    我正在使用像下面这样的 Angular resource angular module app factory data function resource var Con resource api data update method P
  • 从 PHP 数组生成 HTML 表

    我不明白这一点 我需要解决看似简单的问题 但这超出了我的逻辑 我需要编写一个函数 table columns input cols 它将输出一个表 示例 input array apple orange monkey potato chee
  • Highcharts jQuery 渲染问题 - 所有浏览器

    我在尝试使用构建堆积柱形图时遇到了一个奇怪的问题高图表 http www highcharts com 当图表呈现时 在您调整浏览器大小之前 不会显示列无论如何 导致图表重绘 我认为 图表的其余部分显示 轴 标题等 但不显示列本身 我在 I
  • react-native - 图像需要来自 JSON 的本地路径

    你好社区 我正在react native中开发一个测试应用程序 并尝试从本地存储位置获取图像 我实际在做什么 我将图像直接链接源提供给 var 并在渲染函数中调用此方法 react 0 14 8 react native 0 23 1 np
  • 滚动顶部不符合预期

    Note 由于上次忘记奖励而重新开放赏金 A Woff 大师已经给出答案 我想在用户展开某一行时到达该行 这样当最后一个可见行展开时 用户不必向下滚动即可查看内容 I used example tbody on click td green
  • 什么是 WKWebView 中的 WKErrorDomain 错误 4

    fatal error LPWebView encounters an error Error Domain WKErrorDomain Code 4 A JavaScript exception occurred UserInfo 0x7
  • Laravel $request->file() 返回 null

    尝试在后端使用 Laravel 上传文件时遇到问题 Issue Laravel request gt file 方法返回 null Setup 我使用以下方法构建了一个 AJAX 请求超级代理人 https github com visio
  • 使用 php-ews(Exchange Web 服务)在特定日期后获取电子邮件

    在我的 PHP 脚本中 我需要弄清楚如何检索指定消息 ID 之后或特定日期之后的所有电子邮件 两者都可以 我只需要检索自上次抓取收件箱以来的新电子邮件 这个收件箱每天收到数千封电子邮件 而且我在 30 天内无法删除任何电子邮件 对于初始导入
  • 为什么我的会话仍然存在?

    我一定很愚蠢 因为似乎一件相当明显的事情现在让我完全困惑 我有一个会议 ie SESSION handbag id 在某个时刻 我需要彻底终止这个会话 ie at the start of the page session start el

随机推荐