I’ve been through many of the questions/responses relating to this and none of the suggestions have solved the problem.
A bit of back story:
I run a club website and used the inbuilt PHP mail() functionality to be sent emails when a member updated their details. With providers and email relays tightening their security this has become increasingly less reliable. Thus I decided to use PHPMailer to send the emails via GMail. So…
-
Created a user app in Google Cloud.
-
Created an OAuth 2.0 client ID for the app.
-
Used PHPMailer/get_oauth_token.php along with the client ID and
client secret to create a refresh token. -
Added gmail access scopes to the app.
I’m using the example PHPMailer script – https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail_xoauth.phps with my values substituted.
Unfortunately I get the following:
2024-12-15 15:48:46 CLIENT -> SERVER: EHLO myclub.org.uk<br>
2024-12-15 15:48:46 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [79.170.40.34]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8<br>
2024-12-15 15:48:47 CLIENT -> SERVER: AUTH XOAUTH2 dXNlcj1ib2JncmFoYW1jbHViQGdtYWlsLmNvbQFhdXRoPUJlYXJlciB5YTI5LmEwQVJXNW03NzZyNjA3UHNOTjNPWjdjamZTMTJESlZwb09fXzBKdzg1VnBuR05nMWFrcS1JTVBIZENKcjlKZW01dmxBN0tRS05RNF9XUVN0Tks5cVM3eG5HUHhLV1pOMm9OaGVXTnVoYjgyYll6bGFGT2pBX1hheFh3c0J5S1hHRXZTRWx6dUVZZUlldUdLeXpXRlN1VFk1YjhrNi12TWhtTzJOU2NDQ1pOSklEa3hxRE1hQ2dZS0Fha1NBUklTRlFIR1gyTWlBbm9GUk5Cd2V6RlgteGFqeHdDdWdRMDE4MwEB<br>
2024-12-15 15:48:47 SERVER -> CLIENT: 334 eyJzdGF0dXMiOiI0MDAiLCJzY2hlbWVzIjoiQmVhcmVyIiwic2NvcGUiOiJodHRwczovL21haWwuZ29vZ2xlLmNvbS8ifQ==<br>
2024-12-15 15:48:47 SMTP ERROR: AUTH command failed: 334 eyJzdGF0dXMiOiI0MDAiLCJzY2hlbWVzIjoiQmVhcmVyIiwic2NvcGUiOiJodHRwczovL21haWwuZ29vZ2xlLmNvbS8ifQ==<br>
SMTP Error: Could not authenticate.<br>
2024-12-15 15:48:47 CLIENT -> SERVER: QUIT<br>
2024-12-15 15:48:47 SERVER -> CLIENT: 535-5.7.8 Username and Password not accepted. For more information, go to535 5.7.8 https://support.google.com/mail/?p=BadCredentials 5b1f17b1804b1-4363606ece8sm57588185e9.25 - gsmtp<br>
2024-12-15 15:48:47 SMTP ERROR: QUIT command failed: 535-5.7.8 Username and Password not accepted. For more information, go to535 5.7.8 https://support.google.com/mail/?p=BadCredentials 5b1f17b1804b1-4363606ece8sm57588185e9.25 - gsmtp<br>
SMTP Error: Could not authenticate.<br>
Not sure why I get the “Username & Password not accepted” since I’m using OAuth.
Now I’ve missed something (I might also have missed steps I’ve done from the above) or I’ve done something wrong but I’m at a loss to what it is.
Edit: The suggested answer relates to the Zend stack and doesn’t mention anything about an apps password.
Regarding the use of an apps password – this How to use PHPMailer, after 30 May 2022 when “Less secure app” is no longer an option? suggests that it’s no longer an option. Also this suggestion:
- First go to your google account management and go to security.
- Make sure your 2-step verification are enabled.
- Then go to app password.
- Select other in the select app dropdown menu, and named whatever you like.
- And click generate, google will give you a password. make sure you copy it and save it somewhere else.
- instead using your real google account password in PHPMailer setting, use the password you just generate.
No longer seems to be an option, it’s not something that’s apparent in Account->security
2