且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何通过gmail smtp与laravel发送邮件?

更新时间:2023-10-14 08:40:16

需要将您的.env文件更改为以下内容:

Need to change your .env file to something like this:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myemail@gmail.com
MAIL_PASSWORD=apppassword
MAIL_ENCRYPTION=tls

完成.env编辑后,请在您的终端中输入以下命令以清除缓存:

After completion of .env edit please enter this command in your terminal for clear cache:

php artisan config:cache

您需要生成应用密码,并且可以在.env文件中使用该应用密码.

You need to generate app password, and you can use that app password in .env file.

如何生成应用密码:

  1. 转到您的 Google帐户

在左侧导航面板上,单击安全性.

On the left navigation panel, click Security.

登录 Google 面板上,单击应用密码. (注意:如果您无法进入页面,则两步验证为: 未设置您的帐户, 仅设置安全密钥)

On the Signing in to Google panel, click App passwords. (Note: If you can't get to the page, 2-Step Verification is: Not set up for your account, Set up for security keys only)

在底部,单击选择应用程序",然后选择您正在使用的应用程序.

At the bottom, click Select app and choose the app you’re using.

完成后,您将不会再看到该应用的密码.

Once you are finished, you won’t see that App password code again.

注意:您可能无法为安全性较低的应用创建一个应用密码.

Note: You may not be able to create an App password for less secure apps.