I have a free hosting account at 000webhost
. I have configured PHPMailer
to send a message to me in the mail
as soon as someone fills out the feedback form. Messages do not come if the gmail
function allow less secure apps
is disabled.
How to accept gmail
emails without enabling allow less secure apps
. This is my main mail, and I would not like to disable protection on it. It's not here for beauty, is it?) After searching the Internet, I could not find a similar solution. Seems disabling allow less secure apps
suits many. So maybe there is a way to make my hosting account trusted?
Ignore the naysayers, this is entirely possible, and it doesn't involve IMAP.
To be clear, the "allow less secure apps" option only applies to sending email from your gmail account. It has nothing to do with you receiving messages from other people, or how they receive messages sent from you.
Gmail (and others) offers an SMTP authentication mechanism called XOAUTH2, which is, as you might expect, based on OAuth 2.0. If you use this mechanism, you do not need to enable "less secure apps". PHPMailer supports this mechanism, and provides code example showing you how to use it](https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail_xoauth.phps). However, that only shows how to use the auth credentials, not how to get them, which, being OAuth, is a confusing and unpleasant experience. Fortunately there is documentation (which should always be the first place you look before asking questions anyway) and an example script that helps you get the tokens you need. I'm not going to reproduce them here because it just makes more work for me as a maintainer.
The approach is broadly: