通过MailHog,可以在浏览器中查看本机发的邮件内容,而无需发送到外网。
https://github.com/mailhog/MailHog
在 macOS 环境下,下载文件后:
添加可执行权限:chmod +x MailHog_darwin_amd64
运行:./MailHog_darwin_amd64
浏览器打开查看邮件:http://0.0.0.0:8025/
Laravel 发送邮件到 MailHog 使用例子:
Laravel .env:
1 2 3 4 5 6 7 8 9
| MAIL_MAILER=smtp MAIL_DRIVER=smtp MAIL_HOST=127.0.0.1 MAIL_PORT=1025 MAIL_USERNAME=[email protected] MAIL_PASSWORD=xx MAIL_ENCRYPTION= MAIL_FROM_ADDRESS=[email protected] MAIL_FROM_NAME=APP
|
通过 notifications 发送邮件通知:
https://learnku.com/docs/laravel/10.x/notifications/14870#0b4ad8
1 2 3 4 5 6 7 8 9 10 11
| public function toMail($notifiable) { $title = '系统通知:' .' 运单-' . $this->data['data']['waybill']->name . ' 有来自 ' . $this->data['user'] . ' 的新留言:'; $line_title = '运单-' . $this->data['data']['waybill']->name . ' 有来自 ' . $this->data['user'] . ' 的新留言:'; return (new MailMessage) ->subject($title) ->line($line_title) ->line($this->data['data']['message']) ->action($this->data['data']['waybill']->name, url('waybill/') .'/'. $this->data['id']) ->line('Thank you for using our application!'); }
|