首页 > 解决方案 > Laravel - 无法与主机 smtp.googlemail.com 建立连接:stream_socket_client():无法连接

问题描述

我正在尝试使用本地主机的 Laravel 从 Gmail 发送电子邮件。我收到此错误:

Connection could not be established with host smtp.googlemail.com 
:stream_socket_client(): unable to connect to ssl://smtp.googlemail.com:465 
(A connection attempt failed because the connected party did not properly 
respond after a period of time, or established connection failed because 
connected host has failed to respond.)

我的 .env 文件:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.googlemail.com
MAIL_PORT=465
MAIL_USERNAME=myusername@gmail.com
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=ssl

错误是什么?我需要更改服务器或防火墙中的某些设置吗?

标签: laravelemail

解决方案


在 .env 文件中尝试以下代码:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
mail_username=myusername@gmail.com
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=tls

推荐阅读