How to Log Outgoing Emails in Laravel (Full Guide + Open Source Package)

Sooner or later once your Laravel app gets serious and starts having real customers, you’ll probably want to log outgoing emails in Laravel. Whether it’s for quality checks, debugging, or compliance, having a proper Laravel email logging setup becomes important.

I’ve run into this multiple times myself, and I’ve also seen clients trying different workarounds to track outgoing emails in Laravel. Things like forwarding all outgoing emails to another address, or just adding everything to BCC.

Those approaches can work at the beginning, but they don’t really give you a clean or reliable way to store and review sent emails in Laravel, especially once things scale.

To properly solve this problem across my own projects and companies, I decided to build a package that simply logs all outbound emails to the database in Laravel.

The idea was to keep it as seamless as possible, while still allowing flexibility like optional header and body logging, plus scheduled cleanup of older records. Basically something that works out of the box, but still covers real-world needs like Laravel email debugging and maintaining an email audit log.

The package is called Laravel Outbound Email Log, it’s open source and available on GitHub.

Once installed and enabled, the package automatically logs all outgoing emails in Laravel, including:

  • subject
  • from / to / cc / bcc
  • HTML or text body (configurable)
  • headers (configurable)
  • attachment filenames
  • mailable or notification class (when available)
  • mailer name
  • status (sending then sent)
  • sent timestamp

All of these are stored in a dedicated database table, so you get a proper Laravel email history that you can query, filter, or build UI on top of.

With the included model, you can easily build your own interface to view and manage these logs. And if you’re already using Filament, it’s even easier to just spin up a resource and get a full email log dashboard in Laravel in a few minutes.

How to use it in your Laravel app

Getting started with this is pretty straightforward, you don’t need to change anything in how you normally send emails in Laravel.

First, install the package via Composer:

composer require empinet/laravel-outbound-mail-log

Then publish the migration and run it:

php artisan vendor:publish --tag="outbound-mail-log-migrations"

php artisan migrate

After that, enable the package in your .env:

OUTBOUND_MAIL_LOG_ENABLED=true

At this point, that’s basically it. From here on, every outgoing email sent by your app will be logged automatically.

You don’t need to change your existing mailables, notifications, or anything else. Just send emails the way you always do:

use Illuminate\Support\Facades\Mail;

Mail::raw('Hello from the app', function ($message): void {

    $message->to('[email protected]')

        ->from('[email protected]')

        ->subject('Test message');

});


Now if you want to inspect logged emails in Laravel, you can simply query the database:

use Empinet\OutboundMailLog\Models\OutboundMailLog;

$latest = OutboundMailLog::query()->latest('id')->first();

That gives you access to the full email log record, including recipients, subject, body, headers, attachments and send status.

If you want to take it a step further, you can quickly build a small UI on top of this. And if you’re using Filament, it’s honestly just a couple of minutes to turn this into a full Laravel email log dashboard.

If you’re planning to use this in production, you might want to be a bit careful with logging full email bodies, especially if there’s sensitive data involved.

You can control that via config:

OUTBOUND_MAIL_LOG_LOG_BODY=false

Also, since this can grow over time, there’s a built-in cleanup command to remove old records and keep your Laravel email logs under control.

Leave a Reply