Laravel - 无法与主机 smtp.gmail.com 建立连接 [#0] [英] Laravel - Connection could not be established with host smtp.gmail.com [ #0]
问题描述
我正在尝试使用本地主机的 Laravel 从 Gmail 发送电子邮件.我收到此错误:无法与主机 smtp.gmail.com 建立连接 [#0]
I'm trying to send an email from Gmail using Laravel from localhost. I'm getting this error: Connection could not be established with host smtp.gmail.com [ #0]
我正在使用端口 465 的 ssl.我也尝试了 587,但它不起作用.
I'm using ssl with port 465. I also tried 587 but it didn't work.
我也试过 这个 但它没有用.我发现很多人遇到同样的问题,但我找到的解决方案不起作用.
I also tried this but it didn't work. I found a lot of people suffering from the same problems, but the solutions I found didn't work.
推荐答案
编者注:禁用 SSL 验证具有安全隐患.如果不验证 SSL/HTTPS 连接的真实性,恶意攻击者可以冒充一个受信任的端点(例如 GitHub 或其他远程 Git 主机),您将容易受到 中间人攻击.
Editor's note: disabling SSL verification has security implications. Without verification of the authenticity of SSL/HTTPS connections, a malicious attacker can impersonate a trusted endpoint (such as GitHub or some other remote Git host), and you'll be vulnerable to a Man-in-the-Middle Attack.
在 Laravel 项目目录中,编辑 config/mail.php
并添加以下内容:
In Laravel project directory, edit config/mail.php
and add the following:
'stream' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
]
它对我有用.
仅供参考,我的 SMTP 设置是:
Fyi, my SMTP settings are:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=[Full Gmail Address]
MAIL_PASSWORD=[Google App Password obtained after two step verification on Google Account Page]
MAIL_ENCRYPTION=ssl
这篇关于Laravel - 无法与主机 smtp.gmail.com 建立连接 [#0]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!