empinet / laravel-outbound-mail-log
Log outbound emails sent by Laravel into a database table.
Package info
github.com/Empinet/laravel-outbound-mail-log
pkg:composer/empinet/laravel-outbound-mail-log
Requires
- php: ^8.2
- illuminate/console: ^10.0 || ^11.0 || ^12.0
- illuminate/database: ^10.0 || ^11.0 || ^12.0
- illuminate/events: ^10.0 || ^11.0 || ^12.0
- illuminate/mail: ^10.0 || ^11.0 || ^12.0
- illuminate/support: ^10.0 || ^11.0 || ^12.0
Requires (Dev)
- laravel/pint: ^1.18
- orchestra/testbench: ^8.0 || ^9.0 || ^10.0
- phpunit/phpunit: ^10.5 || ^11.0 || ^12.0
This package is auto-updated.
Last update: 2026-03-29 10:42:07 UTC
README
Log outbound emails sent by Laravel into a database table.
This package listens to Laravel's mail sending events and stores outgoing email metadata (subject, recipients, sender, body, headers, attachments, mailable/notification class, mailer, and send status) so you can inspect what was sent.
What gets logged
- subject
- from / to / cc / bcc
- HTML or text body (configurable)
- headers (configurable)
- attachment filenames
- mailable or notification class (when available)
- mailer name
- status (
sendingthensent) - sent timestamp
Installation
Install the package with Composer:
composer require empinet/laravel-outbound-mail-log
Publish and run the migration:
php artisan vendor:publish --tag="outbound-mail-log-migrations"
php artisan migrate
You can also use the default Laravel migration publish tag:
php artisan vendor:publish --tag="migrations"
php artisan migrate
Publish the config file:
php artisan vendor:publish --tag="outbound-mail-log-config"
You can also use the default Laravel config publish tag:
php artisan vendor:publish --tag="config"
Configuration
The package ships disabled by default.
Set this in your .env:
OUTBOUND_MAIL_LOG_ENABLED=true
Available config options (config/outbound-mail-log.php):
return [ 'enabled' => env('OUTBOUND_MAIL_LOG_ENABLED', false), 'cleanup_records_after' => env('OUTBOUND_MAIL_LOG_CLEANUP_RECORDS_AFTER', false), 'log_headers' => env('OUTBOUND_MAIL_LOG_LOG_HEADERS', true), 'log_body' => env('OUTBOUND_MAIL_LOG_LOG_BODY', true), ];
Recommended .env values for local/testing:
OUTBOUND_MAIL_LOG_ENABLED=true OUTBOUND_MAIL_LOG_LOG_BODY=true OUTBOUND_MAIL_LOG_LOG_HEADERS=true OUTBOUND_MAIL_LOG_CLEANUP_RECORDS_AFTER=false
For production, consider setting OUTBOUND_MAIL_LOG_LOG_BODY=false if emails may contain sensitive content.
Usage
After installing, publishing migrations, and enabling the package, send mail normally using Laravel mailables/notifications.
use Illuminate\Support\Facades\Mail; Mail::raw('Hello from the app', function ($message): void { $message->to('user@example.com') ->from('noreply@example.com') ->subject('Test message'); });
Then inspect logs from your app:
use Empinet\OutboundMailLog\Models\OutboundMailLog; $latest = OutboundMailLog::query() ->latest('id') ->first();
Cleanup command
To remove old records based on OUTBOUND_MAIL_LOG_CLEANUP_RECORDS_AFTER, run:
php artisan outbound-mail-log:cleanup
Set OUTBOUND_MAIL_LOG_CLEANUP_RECORDS_AFTER=false to disable cleanup.
To schedule cleanup daily, add this in your routes/console.php:
use Illuminate\Support\Facades\Schedule; Schedule::command('outbound-mail-log:cleanup')->daily();
Notes
- A log entry is created when sending starts (
sending) and marked assentafter Laravel dispatchesMessageSent. - The package supports Mailables, Notification mail channel messages, and closure/raw emails.
Testing
composer test
Releasing
- Releases are tag-based.
- Every push to
mastertriggers thereleaseworkflow and creates the next patch tag automatically. - If no tag exists yet, the workflow bootstraps the first release at
v1.0.0. - You can also run the
releaseworkflow manually and pass an explicit version like1.2.0. - Packagist updates are handled via Packagist auto-update integration.
If Composer shows could not detect the root package version in local development, that is normal before your first release tag. It does not affect package behavior.
Changelog
Please see CHANGELOG for recent changes.
License
The MIT License (MIT). See LICENSE.