1、在 Windows 10 中安装 MailHog ,方便我们开发 Laravel 时对邮件发送的监控。原因在于开发环境是本地主机环境,并非 Homestead 或者 Docker 。打开网址:https://github.com/mailhog/MailHog 。
2、选择 MailHog_windows_amd64.exe ,如图1
3、运行下载的文件后,界面,如图2
[APIv1] BROADCAST /api/v1/events 2021/12/31 11:20:12 [SMTP 127.0.0.1:64569] Session ended [APIv2] GET /api/v2/jim [APIv2] GET /api/v2/messages [APIv2] GET /api/v2/websocket [APIv1] KEEPALIVE /api/v1/events [APIv1] GET /api/v1/messages/9u2mG73gOYyJTHv5yUKHcTGqLrdsdsvzl88MrKPxBlw=@mailhog.example [APIv1] KEEPALIVE /api/v1/events [APIv1] KEEPALIVE /api/v1/events [APIv1] KEEPALIVE /api/v1/events [APIv1] KEEPALIVE /api/v1/events [APIv1] KEEPALIVE /api/v1/events [APIv1] KEEPALIVE /api/v1/events [APIv1] KEEPALIVE /api/v1/events [APIv1] KEEPALIVE /api/v1/events [APIv1] KEEPALIVE /api/v1/events
4、在浏览器中打开网址:http://larabbs.local:8025/ 。如图3
5、Laravel 的 .env 文件中修改 Email 相关设置如下来开启 MailHog
MAIL_MAILER=smtp MAIL_HOST=127.0.0.1 MAIL_PORT=1025 MAIL_USERNAME=null MAIL_PASSWORD=null MAIL_ENCRYPTION=null MAIL_FROM_ADDRESS=admin@larabbs.local MAIL_FROM_NAME="${APP_NAME}"
6、接下来浏览器访问 larabbs.local/register ,填写表单并注册一个测试用户。注册成功后,访问 larabbs.local:8025/ 查看 MailHog 。可见邮件成功发送。如图4
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/250697.html