I am trying to send email from my laravel 5.1 system. I can send emails from my localhost and unable to send from the server. See my email configuration settings in .env file,
MAIL_DRIVER=smtp
MAIL_HOST= smtp.gmail.com
MAIL_PORT= 587
MAIL_USERNAME= username***@gmail.com
MAIL_PASSWORD= *********
MAIL_ENCRYPTION=tls
This configuration only work on my localhost. On server I am getting this error,
Swift_TransportException in StreamBuffer.php line 268:
Connection could not be established with host smtp.gmail.com [Network is unreachable #101]
I also try with changing MAIL_PORT
from 587
to 465
and MAIL_ENCRYPTION
from tls
to ssl
. But I am geeitng the same error. How can I fix this issue?
I solved my problem in cpanel using the code:
change MAIL_DRIVER=smtp to MAIL_DRIVER=sendmail in ".env" file
1.) clear the cache on the server after changing the configuration in the .env file.
php artisan cache:clear;
php artisan config:cache;
and if the error still comes
Connection refused is a very explicit and clear error message. It means that the socket connection could not be established because the remote end actively refused to connect.
It's very unlikely that Google is blocking the connection.
It's very likely that your web hosting provider has firewall settings that block outgoing connections on port 465, or that they are blocking SMTP to Gmail. 465 is the "wrong" port for secure SMTP, though it is often used, and Gmail does listen there. Try port 587 instead. If the connection is still refused, call your host and ask them what's up.
If your website URL is http://yourdomain.com
you need to use this port 587
or if your website URL is https://yourdomain.com
you need to use this port 25
acces to your server and edit
nano /etc/csf/csf.conf
SMTP_ALLOWUSER = "cpanel,yourusr"
Localhost -> worked
Production -> Not Worked
Review your Production Firewall policies or Hosting Provider policies if they blocks email ports (because those ports were heavily spammed)