The connection could not be established with the host smtp.gmail.com.
Today, we will solve a Connection that could not be established with the host smtp.gmail.com in the Laravel application. I’m trying to send an email from Gmail using Laravel from the local host. but getting below error Connection could not be established with host smtp.gmail.com ?.
Error like:
The connection could not be established with the host smtp.gmail.com.
Laravel mail error best solutions for established with host smtp.gmail.com.
The connection could not be established with host smtp.gmail.com[connection refused #111]
.env file
localhost server
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=example@gmail.com
MAIL_PASSWORD=*********
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="example@domain.com"
MAIL_FROM_NAME="${APP_NAME}"
Live server
MAIL_DRIVER=sendmail
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=example@gmail.com
MAIL_PASSWORD=*********
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="example@domain.com"
MAIL_FROM_NAME="${APP_NAME}"
And also replace MAIL_MAILER=sendmail in mail.php file.
#config/mail.php
#old code
'default' => env('MAIL_MAILER', 'smtp'),
#new code
'default' => env('MAIL_MAILER', 'sendmail'),
