惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
WordPress大学
WordPress大学
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The Cloudflare Blog
U
Unit 42
D
Docker
Hugging Face - Blog
Hugging Face - Blog
博客园 - 聂微东
Recent Announcements
Recent Announcements
GbyAI
GbyAI
T
The Blog of Author Tim Ferriss
Last Week in AI
Last Week in AI
V
Visual Studio Blog
I
InfoQ
Google DeepMind News
Google DeepMind News
小众软件
小众软件
L
LangChain Blog
C
Check Point Blog
宝玉的分享
宝玉的分享
Martin Fowler
Martin Fowler
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 【当耐特】
J
Java Code Geeks
罗磊的独立博客

mafeifan 的编程技术分享

mafengwo-mp3-downloader | mafeifan 的编程技术分享 示例页面 | mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 查看 default namespace 下的 default service account名称 mafeifan 的编程技术分享 检查日志 | mafeifan 的编程技术分享 bridge fdb show dev flannel.1 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享
mafeifan 的编程技术分享
2026-01-16 · via mafeifan 的编程技术分享

每次发送邮件自动记录日志

根据文档说明

Laravel 在处理邮件消息发送时触发两个事件。MessageSending 事件在消息发送前触发,MessageSent 事件则在消息发送后触发。 切记,这些事件是在邮件被 发送 时触发,而不是在队列化的时候。可以在 EventServiceProvider 中注册此事件的侦听器:

希望实现:每当邮件发送出去,就将一些基本信息(邮件发件人,收件人,邮件标题等)记录到相关的日志文件中,

  1. 打开 App\Providers\EventServiceProvider

修改

php

    protected $listen = [
        Registered::class => [
            SendEmailVerificationNotification::class,
        ],

        'Illuminate\Mail\Events\MessageSent' => [
            'App\Listeners\EmailLogSentMessage',
        ],
    ];
  1. 执行 php artisan make:listener EmailLogSentMessage

  2. 打开新创建的 App\Listeners\EmailLogSentMessage

  3. 修改handle方法

php

    public function handle($event)
    {
        // 这里只打印了邮件头信息,邮件内容比较长,就不让输出了
        \Log::channel('emailSend')->info($event->message->getHeaders());
    }
  1. 这里需要打开 config\logging, channels 下面添加一节 意思我希望输出日志,按天轮回,并且指定了输出日志的路径和文件名

php

'channels' => [
        'stack' ...
        
        'emailSend' => [
            'driver' => 'daily',
            'path' => storage_path('logs/emailSend.log'),
            'level' => 'info',
            'days' => 14,
        ],
        
        ...

每次发送邮件把日志记录到数据库中

机制一样,根据MessageSending事件搞事情,直接安装这个laravel-email-database-log即可