无法通过Oauth Google发送电子邮件PHPMailer 6.0 [英] Can't Send Email PHPMailer 6.0 with Oauth Google

查看:98
本文介绍了无法通过Oauth Google发送电子邮件PHPMailer 6.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

0与Google Oauth,我收到此错误

0 with Google Oauth and i get this error

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';
}

我没有任何想法,我已经完成了对google的搜索,但没有找到任何解决方案.在我问无法通过Oauth Google发送PHPMailer

i don't have any idea, i've done search google but i dont find any solution. Before i ask in Can't Send PHPMailer with Oauth Google

我的案子有解决办法吗?

Any solution for my case?

推荐答案

几件事:

首先,无论如何,OAuth确实很难调试.我真的建议您看看 6.0分支,其中的OAuth支持显着改善.它附带了更好的示例,如果您可以帮助测试它将非常有用.第二步是关键点,可能会解决您的问题.初始化方面略有不同(请使用PHPMailerOAuth类),因此请仔细阅读文档.

First, OAuth is really hard to debug anyway. I really recommend that you take a look at the 6.0 branch, in which the OAuth support is significantly improved. It comes with much better examples, and it would be very useful if you could help test it. This second step is key point and might solve your problem. There is slight difference in initiation( Use PHPMailerOAuth class), so please read the docs carefully.

第二,通过文档,您可能已经遵循了,但是看看是否缺少任何步骤.

Second, Go through this documentation, you might have followed it, but see if you are missing any step.

第三,您确定获得刷新令牌而不是普通令牌吗?

Third, Are you sure you got a refresh token and not a normal token?

尝试这些方法,让我知道,是否对您有用?

Try these things and let me know, if it worked for you or not?

这篇关于无法通过Oauth Google发送电子邮件PHPMailer 6.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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