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 错误:无法进行身份验证 的相关文章

  • Slim 3 - 斜杠作为路由参数的一部分

    我需要使用可以包含斜杠 的参数来编写 URL 例如 经典的 hello username 路线 默认情况下 hello Fabien将匹配此路线 但不匹配 hello Fabien Kris 我想问你如何在 Slim 3 框架中做到这一点
  • 如果文件名减去扩展名,.htaccess url 重写行为将被覆盖。与网址相同

    我正在尝试整理 URL 并从中删除 php 扩展名等 我位于网站的基本文件夹中 因此没有可以优先处理的父 htaccess 文件或其他文件 这是我的 htaccess 代码 RewriteEngine On RewriteRule give
  • 如何在php中关闭夏令时

    我有这行代码将夏令时设置为 打开 将其设置为 关闭 的正确方法是什么 is daylight saving On rcmail config dst active bool date I date I 这是一个大写字母 i 当当前默认时区
  • fadeOut() 和slideUp() 同时进行?

    我已经发现jQuery 淡出然后滑动 https stackoverflow com questions 734554 jquery fadeout then slideup这很好 但不是那个 我怎么能够fadeOut and slideU
  • 自调用函数未定义

    如果我声明一个函数文字 var x function alert hi console log x returns the function code However var x function alert hi console log
  • 为什么函数声明在不同浏览器中的处理方式不同?

    虽然我在谷歌中找不到对此的引用 但我熟悉这样一个事实 在 javascript 中 全局函数声明在执行任何代码之前都会被解释 换句话说 这工作得很好 f function f 但是 我注意到 chrome 和 firefox 对全局函数声明
  • Javascript:我应该隐藏我的实现吗?

    作为一名 C 程序员 我有一个习惯 将可以而且应该私有的东西设为私有 当 JS 类型向我公开其所有私有部分时 我总是有一种奇怪的感觉 而且这种感觉并没有被 唤起 假设我有一个类型draw方法 内部调用drawBackground and d
  • 冒泡可用于图像加载事件吗?

    我可以用吗 window addEventListner 某种程度上来说 我所有的图像都有一个display none 图像加载后 我想设置display inline 这样我就可以规范下载图像时显示的内容 在这种情况下 我无法预加载图像
  • 如何在具有相同值的下拉菜单上触发 jQuery 更改事件

    即使用户选择相同的值 如何每次都触发 jQuery 更改事件 我需要刷新效果 例如如果用户选择Lawyer它会发出警报hello然后用户再次选择Lawyer从下拉菜单中 它应该发出警报hello 我怎样才能实现它 以下是代码 jQuery
  • 如何根据另一个下拉列表中的选择动态填充下拉列表中的选项?

    我有一个表 其中包含类别信息 例如产品 我已将它们列在下拉菜单中 现在 我需要做的是 在下一个下拉菜单中列出所选类别的子类别 我希望 javascript 是必需的 但我对 javascript 还不太熟悉 将非常感谢您的帮助 你应该使用
  • JSONP 使用 JQuery 从 HTTPS 协议获取 JSON

    我正在尝试获取从 https 安全站点发送的 JSON 客户端希望不要使用任何服务器端语言 全部都是 Javascript 我读到 当使用 Jquery 中的 ajax 函数时 我必须使用 JSONP 才能从安全站点加载 JSON 我的第一
  • 由于未定义符号,PECL solr 未加载:curl_easy_getinfo

    我正在尝试加载 PECL solr 扩展 我尝试使用 pecl install solr 并下载并使用 phpize configure make 来安装它 在这两种情况下 扩展安装时都没有错误 但在 apache 重新启动后 或在命令行上
  • 使用 PHP 创建图表并导出为 PDF

    我正在寻找有关使用 PHP 创建图表的建议 我还希望能够将这些图表导出到 PDF 文档 我目前正在使用谷歌图表 但我不喜欢将我的所有信息发送到谷歌的想法 我更喜欢自己的托管解决方案 我见过很多 Flash 解决方案 但我不知道有什么方法可以
  • D3 向对象添加超链接?

    我正在尝试制作 D3 图 它将代表我网站的菜单 我尝试按照此处的其他指南添加超链接 但它们都不起作用 每个对象都会有一个不同的 URL 指向 主页 关于 联系方式等 如果添加超链接 我可以拖动对象吗 这意味着如果我按住单击 如果我单击该对象
  • 如何使用 GreaseMonkey 让浏览器恢复“/”键?

    Lots of web pages seem to use the key for searching I d like to disable that because 100 of the time I want to use to se
  • for循环中需要声明变量吗?

    有什么区别 for var i 0 i lt 5 i for i 0 i lt 5 i 是否有必要包含 var 关键字 我知道 var 关键字会影响变量范围 但我无法理解是否有必要在 for 循环中包含该关键字 在第二个示例中 您的变量是全
  • 如何从除自身之外的其他(blazor)库引用js/css文件?

    我如何引用 使用位于引用的 blazor 项目中的 css cs 文件 该文件与 host cshtml 中的当前项目不同 我的意思是
  • 使用 md5 加密的 PHP 和 Mysql 查询出现问题

    我使用普通的 php mysql 插入查询并使用 md5 加密密码 这是插入查询 sql mysql query INSERT INTO user username password role approved values usernam
  • $ 在 JQuery 中意味着什么

    在下面的 var obj one 1 two 2 three 3 four 4 five 5 each obj function i val console log val 这里是什么意思 是对象吗 是一个别名jQuery对象 函数 它充当
  • HTML 表格 - 固定列宽和多个可变列宽

    我必须建立一个有 5 列的表 表格宽度是可变的 内容宽度的 50 有些列包含固定大小的按钮 因此这些列应该有一个固定大小 例如 100px 有些列中有文本 所以我希望这些列具有可变的列宽 例如 Column1 tablewidth sum

随机推荐