需要使用PHPMailer进行身份验证错误的帮助 [英] Need assistance with authentication errors using PHPMailer

查看:50
本文介绍了需要使用PHPMailer进行身份验证错误的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PHPMailer将电子邮件发送到用户帐户,并且出现了以下错误:

I'm trying to send emails to user's accounts using PHPMailer, and I've been getting these errors:

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. 

我查看了错误,错误中提供的google支持页面以及github上的故障排除指南,但没有找到任何解决方案.我知道我的凭据是正确的(我没有在此处发布真实的凭据).我不想让安全性较差的应用程序访问我的电子邮件,因为所有用户也必须接收他们的电子邮件.另外,我尝试了oAuth2,但是我的重定向url(get_oauth_token.php是我使用的文件)找不到作曲家的自动加载文件:vendor/autoload.php,即使我已经下载并运行了作曲家和狂饮.

I've looked on overflow, the google support page supplied in the error, as well as the troubleshooting guide on github and haven't found any solutions. I know my credentials are right(I didn't post my real credentials on here). I don't want to have to allow less secure apps to access my email, because all users will have to for their emails as well. Also, I have tried oAuth2, but my redirect url(get_oauth_token.php is the file I used) couldn't find composer's autoload file : vendor/autoload.php, even though I have composer and guzzle downloaded and running.

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

Anyway here's the full debug output(SMTP debug is set to 2)

SERVER -> CLIENT: 220 smtp.gmail.com ESMTP g198sm11047892itb.29 - gsmtp
CLIENT -> SERVER: EHLO localhost
SERVER -> CLIENT: 250-smtp.gmail.com at your service, [2602:306:ccb0:63b0:1817`enter code here`:970b:44c3:889b]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
CLIENT -> SERVER: STARTTLS
SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
CLIENT -> SERVER: EHLO localhost
SERVER -> CLIENT: 250-smtp.gmail.com at your service, [2602:306:ccb0:63b0:1817:970b:44c3:889b]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
CLIENT -> SERVER: MAIL FROM:<no-reply@random>
SERVER -> CLIENT: 530-5.5.1 Authentication Required. Learn more at530 5.5.1 https://support.google.com/mail/?p=WantAuthError g198sm11047892itb.29 - gsmtp
SMTP ERROR: MAIL FROM command failed: 530-5.5.1 Authentication Required. Learn more at530 5.5.1 https://support.google.com/mail/?p=WantAuthError g198sm11047892itb.29 - gsmtp
The following From address failed: no-reply@random: MAIL FROM command failed,Authentication Required. Learn more at https://support.google.com/mail/?p=WantAuthError g198sm11047892itb.29 - gsmtp,530,5.5.1SMTP server error: MAIL FROM command failed Detail: Authentication Required. Learn more at https://support.google.com/mail/?p=WantAuthError g198sm11047892itb.29 - gsmtp SMTP code: 530 Additional SMTP info: 5.5.1
Mailer Error: The following From address failed: no-reply@random: MAIL FROM command failed,Authentication Required. Learn more at https://support.google.com/mail/?p=WantAuthError g198sm11047892itb.29 - gsmtp ,530,5.5.1SMTP server error: MAIL FROM command failed Detail: Authentication Required. Learn more at https://support.google.com/mail/?p=WantAuthError g198sm11047892itb.29 - gsmtp SMTP code: 530 Additional SMTP info: 5.5.1SMTP server error: MAIL FROM command failed Detail: Authentication Required. Learn more at https://support.google.com/mail/?p=WantAuthError g198sm11047892itb.29 - gsmtp SMTP code: 530 Additional SMTP info: 5.5.1CLIENT -> SERVER: QUIT
SERVER -> CLIENT: 221 2.0.0 closing connection 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 .

Uh, it's failing to authenticate because you're telling it not to use authentication! Set $mail->SMTPAuth = true;. If you want to see useful debug output, set SMTPDebug = 2.

此外,通过gmail发送邮件时,完全不需要禁用证书检查.这是一个非常糟糕的主意-启用它.

Also, there is absolutely no need to disable certificate checking when sending via gmail. It's a really bad idea - leave it enabled.

这篇关于需要使用PHPMailer进行身份验证错误的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆