【发布时间】:2018-01-11 23:38:03
【问题描述】:
使用 Google Oauth 为 0,我收到此错误
2017-08-04 06:38:42 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP v19sm895098pgc.93 - gsmtp
2017-08-04 06:38:42 CLIENT -> SERVER: EHLO localhost
2017-08-04 06:38:43 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [180.243.143.147]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
2017-08-04 06:38:43 CLIENT ->; SERVER: STARTTLS
2017-08-04 06:38:43 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2017-08-04 06:38:43 CLIENT -> SERVER: EHLO localhost
2017-08-04 06:38:43 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [180.243.143.147]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
SMTP Error: Could not authenticate.
2017-08-04 06:38:43 CLIENT -> SERVER: QUIT
2017-08-04 06:38:43 SERVER -> CLIENT: 221 2.0.0 closing connection v19sm895098pgc.93 - gsmtp
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
我的脚本
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require './vendor/autoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->AuthType = 'XOAUTH2';
$mail->oauthUserEmail = "info@modelunitednation.org";
$mail->oauthClientId = "932857915584-eco8v9aejdb2n3mkltgvftf8e5h1eiko.apps.googleusercontent.com";
$mail->oauthClientSecret = "7SqFo7aPYvZ05cHlh5p3kMUD";
$mail->oauthRefreshToken = "1/4KJJ5XMyXqELMAhRXGYjz_I4SfoWfFR9N9RRA2VA2I0";
$mail->addAddress('jakabanasuy2@gmail.com'); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->setFrom('from@example.com', 'Mailer');
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
我没有任何想法,我已经完成了谷歌搜索,但我没有找到任何解决方案。在我问之前Can't Send PHPMailer with Oauth Google
我的情况有什么解决方案吗?
【问题讨论】:
-
如果要使用 6.0 分支,请使用the oauth example from the same branch;它不像以前那样工作了。
-
谢谢 :) 它为我工作
标签: php oauth-2.0 phpmailer google-oauth