Gmail SMTP issue with Hosted Website but working on xampp
I get this error:
production.INFO: Failed to authenticate on SMTP server with username "[email protected]" using the following authenticators: "LOGIN", "PLAIN". Authenticator "LOGIN" returned "Expected response code "235" but got code "535", with message "535 Incorrect authentication data".". Authenticator "PLAIN" returned "Expected response code "235" but got code "535", with message "535 Incorrect authentication data".
production.ERROR: Failed to authenticate on SMTP server with username "[email protected]" using the following authenticators: "LOGIN", "PLAIN". Authenticator "LOGIN" returned "Expected response code "235" but got code "535", with message "535 Incorrect authentication data".". Authenticator "PLAIN" returned "Expected response code "235" but got code "535", with message "535 Incorrect authentication data".". {"exception":"[object] (Symfony\\Component\\Mailer\\Exception\\TransportException(code: 535): Failed to authenticate on SMTP server with username \"[email protected]\" using the following authenticators: \"LOGIN\", \"PLAIN\". Authenticator \"LOGIN\" returned \"Expected response code \"235\" but got code \"535\", with message \"535 Incorrect authentication data\".\". Authenticator \"PLAIN\" returned \"Expected response code \"235\" but got code \"535\", with message \"535 Incorrect authentication data\".\". at /to/path/vendor/symfony/mailer/Transport/Smtp/EsmtpTransport.php:212)
The problem is that I don't get any issue and the emails are working on xampp but this only happens on my uploaded website. (Even worse, this has only recently started, maybe 15 days back and it was working before on uploaded website too)
Double-check the SMTP username and password for the production environment. It’s possible that incorrect credentials are being used. These may differ from your local setup, where you might be using different credentials.
Action: Verify the MAIL_USERNAME and MAIL_PASSWORD in the production .env file. Make sure they match exactly with your actual Gmail credentials.
IP/Server Restrictions
Sometimes, the IP of the production server is blocked by Google because it sees the login attempt as suspicious (especially if the local environment is on a trusted home IP and the production server is on an unknown IP).
Solution: Log in to the Gmail account and check for security alerts. If you find any, confirm that the login attempt was you, and whitelist the production server's IP.
Gmail SMTP Configuration
Ensure that your .env configuration has the correct settings. Here’s an example of the correct configuration:
They are correct. I keep the same local and production variables. I am a one man team so I don't even need to replace and complicate my work for both env (Except for needful situations).
The username is the email address used for logging into the gmail and the password was generated from the "App Passwords" portion (Since Non-Secure Login option is not available with 2FA). It's working local XAMPP, it should work in production cpanel.
I didn't receive any security alert email. I don't see any other security section of the Google Account where it shows some login attempts either.
SMTP Configs are exactly absolutely same.
I've played around with the encryptions too, just to verify. No combination works. (It's configured correct):
Anywhere I find similar issue threads, they keep mentioning the 2FA-UnsecureApps-AppPassword solution, which I know and I've already configured. Not to forget it's working on my XAMPP.
I've talked to my hosting provider and they say they didn't put any SMTP restrictions from WHM.