使用 Gmail 从 Laravel 发送电子邮件

Sending email from Laravel using Gmail

我已经使用 Laravel 一段时间了,所以我想我会深入研究 HTML 电子邮件,所以我遵循了一个教程。

我遇到的问题以及其他似乎很多问题是这样的:

Swift_TransportException in StreamBuffer.php line 269:

Connection could not be established with host smtp.gmail.com 
[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.
#10060]

我的.ENV

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=EMAIL
MAIL_PASSWORD=PASS
MAIL_ENCRYPTION=tls

我也尝试过端口 25 和其他建议的端口,以及 ssl 而不是 tls,我也尝试过使用 sendmail 而不是 smtp。

除此之外,我在尝试使用 Outlook 帐户时遇到了同样的问题。

我什至启用了接受来自不太安全的应用程序的项目的选项。

还有其他人遇到这些问题吗?

更新:

我在使用 Mail Trap 时遇到了同样的问题,这可能是我的 laravel 安装造成的吗?

还尝试了全新安装...

进一步更新

当我 ping 任何站点时,我收到请求超时,这意味着我认为我的路由器阻止了我?

根据 Google 管理员页面的帮助,当您尝试通过端口 465 连接时,这需要加密 SSL,相反,如果您使用 TLS,则应将端口设置为 587,请尝试更改端口在你的 .env 文件上。

参考:https://support.google.com/a/answer/176600?hl=es

.env 文件

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=youremailaddress
MAIL_PASSWORD=yourownpassword
MAIL_ENCRYPTION=tls