Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ajit_13's avatar

Connection could not be established with host "ssl://smtp.gmail.com:465"

Hello everyone, my project is running fine on live servers, but when i am sending a forgotten email, it shows an error.

Connection could not be established with host "ssl://smtp.gmail.com:465": stream_socket_client(): Unable to connect to ssl://smtp.gmail.com:465 (Network is unreachable)

please guide me on how to resolve it, at the local server it works fine, I have changed the port to 465 and encryption to SSL.

0 likes
9 replies
LaryAI's avatar
Level 58

The error message suggests that the server is unable to connect to the SMTP host. This could be due to a number of reasons such as firewall restrictions, network issues, or incorrect SMTP settings.

Here are a few things you can try to resolve the issue:

  1. Check if the SMTP host is reachable from the server. You can use the ping command to test the connectivity. For example, ping smtp.gmail.com should return a response from the server.

  2. Check if the firewall is blocking the outgoing traffic on port 465. You may need to open the port in the firewall settings.

  3. Verify that the SMTP settings are correct. Double-check the SMTP host, port, username, and password. Also, make sure that the encryption method is set to SSL.

  4. Try using a different SMTP host or port. Some ISPs may block outgoing traffic on certain ports, so you may need to use a different port or SMTP host.

Here's an example of how to configure Laravel to use Gmail SMTP:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
[email protected]
MAIL_PASSWORD=your-password
MAIL_ENCRYPTION=ssl

Make sure to replace [email protected] and your-password with your actual Gmail credentials.

If none of the above solutions work, you may need to contact your hosting provider or network administrator for further assistance.

1 like
Ajit_13's avatar

@tisuchi I checked the configuration it is correct, I don't understand where the problem is. The Server Side blocks some Port. .env

MAIL_MAILER=smtp MAIL_HOST=smtp.gmail.com MAIL_PORT=587 [email protected] MAIL_PASSWORD=edxmbudngbhybi MAIL_ENCRYPTION=tls MAIL_FROM_ADDRESS="[email protected]" MAIL_FROM_NAME="FYIP"

tisuchi's avatar

@Ajit_13 If you feel everything is correct, then clean your cache.

For example:

php artisan config:clear
php artisan route:clear
php artisan view:clear
php artisan cache:clear
Snapey's avatar

possible issue is that your hosting provider blocks the port either by policy or local firewall.

Snapey's avatar

You say the error is failure to connect to smtp.gmail.com:465. which is saying port 465

You say your config is port 587. ?

ON YOUR SERVER, run artisan tinker and type

config('mail')

and check it returns what you expected

nadsir's avatar

It is because you did not check your email account config you must go to c panel and email section and front of your email choose connect devices and check your out putting server you write wrong information on .env You must add this information

zeineb1999's avatar

please how can i resolve it i have the same problem any help pls ?

Please or to participate in this conversation.