Have you tried tls encryption with port 587
Sending email to Gmail and A2Hosting
Hello everyone, I need to implement a contact form on the website which is built using Laravel. So everything worked fine until I switched to send emails to the dedicated Gmail account.
After plenty of research how to send emails to the Gmail I have done next:
- Two factor authorization turned OFF.
- POP3/IMAP enabled.
- Allow less secure apps turned ON.
- DisplayUnlockCaptcha Account Access Enabled.
Configuration .env file setup:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
[email protected]
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=ssl
After that, I faced “Connection could not be established with host smtp.gmail.com” problem and I solved it by adding next in config/mail.php:
'stream' => [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true,
],
],
After that, I faced: “Failed to authenticate on SMTP server with username "[email protected]" using 2 possible authenticators. Authenticator LOGIN returned Swift_TransportException: Expected response code 235 but got code "535", with message "535 Incorrect authentication data ‘’ in…” problem and I have no idea how to solve it.
For testing purpose I made one email account on my hosting ex. [email protected] and when I replace that informations in .env file like this:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
[email protected]
MAIL_PASSWORD=myhostingaccountpassword
MAIL_ENCRYPTION=ssl
Email was not sent to [email protected] probably because wrong MAIL_HOST but there is no “Failed to authenticate on SMTP server…” error and my own “Message successfully sent” message showing up.
So, if [email protected] works (not showing any erorrs) and [email protected] does not work (showing auth error), I think that the problem is actually in my domain/hosting configuration. To be precise, whatever I type in MAIL_HOST at the end it will hit hosting mail exchange host and not smtp.gmail.com.
Of course I cleared config cache every time I changed config or .env files. I have never used the MailGun service so I will rather avoid it for this small project also.
The application is hosted on A2Hosting. Do I need to change some kind of MX records for specific domain or what else I can do in cPanel to make this works?
Any help and other suggestions are more than welcome!
Please or to participate in this conversation.