Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
需要使用PHPMailer处理身份验证错误的帮助吗_Php_Email_Authentication_Smtp_Phpmailer - Fatal编程技术网

需要使用PHPMailer处理身份验证错误的帮助吗

需要使用PHPMailer处理身份验证错误的帮助吗,php,email,authentication,smtp,phpmailer,Php,Email,Authentication,Smtp,Phpmailer,我正在尝试使用PHPMailer向用户的帐户发送电子邮件,我收到了以下错误: The following From address failed: no-reply@random: MAIL FROM command failed,Authentication Required. SMTP ERROR: MAIL FROM command failed Detail: Authentication Required. SMTP server error: MAIL FROM command f

我正在尝试使用PHPMailer向用户的帐户发送电子邮件,我收到了以下错误:

The following From address failed: no-reply@random: MAIL FROM command failed,Authentication Required. 
SMTP ERROR: MAIL FROM command failed Detail: Authentication Required.
SMTP server error: MAIL FROM command failed Detail: Authentication Required. 
我查看了overflow、错误中提供的google支持页面以及github上的故障排除指南,但没有找到任何解决方案。我知道我的证书是正确的(我没有在这里发布我真正的证书)。我不想让不太安全的应用程序访问我的电子邮件,因为所有用户也必须为他们的电子邮件提供服务。另外,我尝试了oAuth2,但是我的重定向url(get_oauth_token.php是我使用的文件)找不到composer的自动加载文件:vendor/autoload.php,即使我下载并运行了composer和guzzle

无论如何,这是完整的调试输出(SMTP调试设置为2)

SERVER->CLIENT:220 smtp.gmail.com ESMTP g198sm11047892itb.29-gsmtp
客户端->服务器:EHLO本地主机
服务器->客户端:250-smtp.gmail.com随时为您服务,[2602:306:ccb0:63b0:1817`在此处输入代码`:970b:44c3:889b]250-SIZE 35882577250-8bitme250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250-SMTPUTF8
客户端->服务器:STARTTLS
服务器->客户端:220 2.0.0准备启动TLS
客户端->服务器:EHLO本地主机
服务器->客户端:250-smtp.gmail.com为您服务,[2602:306:ccb0:63b0:1817:970b:44c3:889b]250-SIZE 35882577250-8bitmeme250-AUTH登录普通XOAUTH2普通客户端令牌OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-Pipeling250-CHUNKING250-SMTPUTF8
客户端->服务器:邮件发件人:
服务器->客户端:需要530-5.5.1身份验证。在530 5.5.1了解更多信息https://support.google.com/mail/?p=WantAuthError g198sm11047892itb.29-gsmtp
SMTP错误:来自命令的邮件失败:需要530-5.5.1身份验证。在530 5.5.1了解更多信息https://support.google.com/mail/?p=WantAuthError g198sm11047892itb.29-gsmtp
以下发件人地址失败:否-reply@random:MAIL FROM命令失败,需要身份验证。了解更多信息,请访问https://support.google.com/mail/?p=WantAuthError g198sm11047892itb.29-gsmtp,530,5.5.1SMTP服务器错误:来自命令的邮件失败详细信息:需要身份验证。了解更多信息,请访问https://support.google.com/mail/?p=WantAuthError g198sm11047892itb.29-gsmtp SMTP代码:530其他SMTP信息:5.5.1
邮件程序错误:以下发件人地址失败:否-reply@random:MAIL FROM命令失败,需要身份验证。了解更多信息,请访问https://support.google.com/mail/?p=WantAuthError g198sm11047892itb.29-gsmtp,530,5.5.1SMTP服务器错误:来自命令的邮件失败详细信息:需要身份验证。了解更多信息,请访问https://support.google.com/mail/?p=WantAuthError g198sm11047892itb.29-gsmtp SMTP代码:530其他SMTP信息:5.5.1SMTP服务器错误:来自命令的邮件失败详细信息:需要身份验证。了解更多信息,请访问https://support.google.com/mail/?p=WantAuthError g198sm11047892itb.29-gsmtp SMTP代码:530其他SMTP信息:5.5.1客户端->服务器:退出
服务器->客户端:221 2.0.0关闭连接g198sm11047892itb.29-gsmtp
这是我邮寄的文件

<?php
error_reporting(-1);
ini_set('display_errors', 'On');
set_error_handler("var_dump");
require_once('PHPMailer/PHPMailer-master/PHPMailerAutoLoad.php');
 require_once('PHPMailer/PHPMailer-master/class.smtp.php');
 require_once('PHPMailer/PHPMailer-master/class.phpmailer.php');
 date_default_timezone_set('Etc/UTC');
class Mail
{

    public static function sendMail($subject,$body,$address)
    {

//Create a new PHPMailer instance

$mail = new PHPMailer;

$mail->isSMTP();
$mail->SMTPDebug = 1;
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';

$mail->SMTPSecure = 'tls';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;

$mail->SMTPAuth = false;
$mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);

$mail->Username = "random@gmail.com";
$mail->Password = "default";
$mail->SetFrom('no-reply@random');
$mail->addAddress($address);
$mail->Subject = $subject;
$mail->Body = $body;
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}
    }
}

?>

呃,它无法进行身份验证,因为您告诉它不要使用身份验证!设置
$mail->SMTPAuth=true。如果要查看有用的调试输出,请设置
SMTPDebug=2


另外,当通过gmail发送时,绝对没有必要禁用证书检查。这是一个非常糟糕的主意-保持启用状态。

谢谢,现在我收到以下两个错误SMTP错误:无法验证。SMTP错误:密码命令失败:环顾四周后,似乎唯一的解决方案是允许不太安全的应用程序访问我的电子邮件,但正如我所说,我不想让不太安全的应用程序访问我的电子邮件,因为所有用户都必须访问他们的电子邮件,而且这似乎对他们来说是一件麻烦事,有其他选择吗?您可以使用XOAUTH2进行身份验证,这样就不需要启用安全性较低的应用程序。阅读维基了解更多信息。我还建议使用6.0分支,因为oauth支持要好得多。我已经尝试过XOAUTH2,但是我的重定向url(PHPMailer中的get_oauth_token.php就是我使用的文件)找不到composer的自动加载文件:vendor/autoload.php,即使我已经下载并运行了composer和guzzle。是否有其他文件需要下载或以其他方式自动加载该文件?我试着使用谷歌云平台,
autoload.php
是由composer创建的;它不是PHPMailer本身的一部分。使用composer将phpMail添加到应用程序中;不要试图在PHPMailer自己的文件夹中构建脚本。
<?php
error_reporting(-1);
ini_set('display_errors', 'On');
set_error_handler("var_dump");
require_once('PHPMailer/PHPMailer-master/PHPMailerAutoLoad.php');
 require_once('PHPMailer/PHPMailer-master/class.smtp.php');
 require_once('PHPMailer/PHPMailer-master/class.phpmailer.php');
 date_default_timezone_set('Etc/UTC');
class Mail
{

    public static function sendMail($subject,$body,$address)
    {

//Create a new PHPMailer instance

$mail = new PHPMailer;

$mail->isSMTP();
$mail->SMTPDebug = 1;
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';

$mail->SMTPSecure = 'tls';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;

$mail->SMTPAuth = false;
$mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);

$mail->Username = "random@gmail.com";
$mail->Password = "default";
$mail->SetFrom('no-reply@random');
$mail->addAddress($address);
$mail->Subject = $subject;
$mail->Body = $body;
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}
    }
}

?>