我坚持以下奇怪的情况。
尝试将phpMailer与gMail和xoauth2一起使用,并在连接成功时,在发送"请求AUTH"之后命令,我收到了" SMTP错误的响应:无法验证"。
使用phpmailer 5.2.21,使用oauth2联盟1.4.1(全部通过作曲家加载) PHP版本:7.0.1(加载openssl)
配置如下
$mailer = new PHPMailer();
$mailer->isSMTP();
$mailer->Host = 'smtp.gmail.com';
$mailer->SMTPAuth = true;
$mailer->AuthType = 'XOAUTH2';
$mailer->oauthUserEmail = $userEmail;
$mailer->oauthClientId = $clientId;
$mailer->oauthClientSecret = $clientSecret;
$mailer->oauthRefreshToken = $token;
$mailer->SMTPSecure = 'tls';
$mailer->Port = 587;
$mailer->setFrom($email);
$mailer->addAddress($recipient);
$mailer->Subject = $subject;
$mailer->Body = $message;
if (! $mailer->send())
throw new RuntimeException('Mail submission failed! ' . $mailer->ErrorInfo);
调试输出如下:
2017-01-05 08:14:47 Connection: opening to smtp.gmail.com:587, timeout=300, options=array ()
2017-01-05 08:14:47 Connection: opened
2017-01-05 08:14:47 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP e7sm325303lfb.10 - gsmtp
2017-01-05 08:14:47 CLIENT -> SERVER: EHLO survey.kaimakinn.gr
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
2017-01-05 08:14:47 CLIENT -> SERVER: STARTTLS
2017-01-05 08:14:47 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2017-01-05 08:14:47 CLIENT -> SERVER: EHLO survey.kaimakinn.gr
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
2017-01-05 08:14:47 Auth method requested: XOAUTH2
2017-01-05 08:14:47 Auth methods available on the server: LOGIN,PLAIN,XOAUTH2,PLAIN-CLIENTTOKEN,OAUTHBEARER,XOAUTH
2017-01-05 08:14:47 SMTP Error: Could not authenticate.
2017-01-05 08:14:47 CLIENT -> SERVER: QUIT
谷歌应用程序被授权使用Gmail(https://mail.google.com),并且设置应用程序和获取刷新令牌的整个过程都是成功的。此外,我已经完成了整个phpmailer故障排除指南,但没有运气。
我可能在这里遗漏了一些明显的东西,但是有什么想法吗? 提前致谢
答案 0 :(得分:0)
是的,简单的东西 - 错误的课程:
$mail = new PHPMailerOAuth;
查看PHPMailer提供的gmail_xoauth.phps
示例。请注意,在PHPMailer 6.0中将大大改进OAuth支持。