使用PHPMailer需要有关身份验证错误的帮助

时间:2017-05-20 20:09:34

标签: 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 failed Detail: Authentication Required. 

我已查看溢出,错误中提供的Google支持页面,以及github上的故障排除指南,并且找不到任何解决方案。我知道我的凭据是正确的(我没有在这里发布我的真实凭据)。我不想让不太安全的应用访问我的电子邮件,因为所有用户也必须提供电子邮件。此外,我已经尝试过oAuth2,但我的重定向网址(get_oauth_token.php是我使用的文件)无法找到作曲家的自动加载文件:vendor / autoload.php,即使我已经下载了作曲家和guzzle运行。

无论如何,这里是完整的调试输出(SMTP调试设置为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!";
}
    }
}

?>

1 个答案:

答案 0 :(得分:0)

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

此外,在通过gmail发送时,绝对不需要来禁用证书检查。这是一个非常糟糕的主意 - 让它启用。