shaffe / laravel-mail-log-channel
A package to support logging via email in Laravel
Package info
github.com/shaffe-fr/laravel-mail-log-channel
pkg:composer/shaffe/laravel-mail-log-channel
Requires
- php: ^8.1
- illuminate/bus: ^10.0|^11.0|^12.0|^13.0
- illuminate/contracts: ^10.0|^11.0|^12.0|^13.0
- illuminate/database: ^10.0|^11.0|^12.0|^13.0
- illuminate/log: ^10.0|^11.0|^12.0|^13.0
- illuminate/mail: ^10.0|^11.0|^12.0|^13.0
- illuminate/queue: ^10.0|^11.0|^12.0|^13.0
- illuminate/support: ^10.0|^11.0|^12.0|^13.0
- monolog/monolog: ^3.0
README
A service provider to add support for logging via email using Laravels built-in mail provider.
This package is a fork of laravel-log-mailer by Steve Porter.
Features
- Structured error emails with clear sections
- Execution context: HTTP request (method, URL, route, controller, user), Artisan command, or Queue job (connection, queue)
- Environment badges: app environment, Laravel/PHP versions, server hostname
- Code snippet with error line highlighted
- Smart stack trace: application frames visible, vendor frames collapsed
- SQL queries with bindings and execution time
- Additional context from
Exception::context()and log record - Relative file paths for readability
- Previous exception chain display
- Clickable file paths to open directly in your editor (via
app.editorconfig)
Table of contents
Installation
You can install this package via composer using this commande:
composer require shaffe/laravel-mail-log-channel
Laravel version compatibility
| Laravel | Package |
|---|---|
| 10, 11, 12, 13 | ^3.0 |
| 5.6, 6, 7, 8, 9, 10, 11, 12, 13 | ^2.0 |
| 5.6.x | ^1.0 |
The package will automatically register itself.
Configuration
To ensure all unhandled exceptions are mailed:
- create a
maillogging channel inconfig/logging.php, - add this
mailchannel to your current logging stack, - add a
LOG_MAIL_ADDRESSto your.envfile to define the recipient.
You can specify multiple channels and individually change the recipients, the subject and the email template.
'channels' => [ 'stack' => [ 'driver' => 'stack', // 2. Add mail to the stack: 'channels' => ['single', 'mail'], ], // ... // 1. Create a mail logging channel: 'mail' => [ 'driver' => 'mail', 'level' => env('LOG_MAIL_LEVEL', 'notice'), // Specify mail recipient 'to' => [ [ 'address' => env('LOG_MAIL_ADDRESS'), 'name' => 'Error', ], ], 'from' => [ // Defaults to config('mail.from.address') 'address' => env('LOG_MAIL_ADDRESS'), // Defaults to config('mail.from.name') 'name' => 'Errors' ], // Show all vendor frames in stack trace (collapsed by default) // 'collapse_vendor_frames' => true, // Disable SQL query collection in error emails // 'log_queries' => false, // Optionally overwrite the subject format pattern // Available placeholders: %level_name%, %message%, %env%, %context%, %app_name%, %channel%, %datetime% // 'subject_format' => '[%level_name%] [%env%] %context% — %message%', // Optionally overwrite the mailable template // Two variables are sent to the view: `string $content` and `array $records` // 'mailable' => NewLogMailable::class ], ],
Recipients configuration format
The following to config formats are supported:
-
single email address:
'to' => env('LOG_MAIL_ADDRESS', ''),
-
array of email addresses:
'to' => explode(',', env('LOG_MAIL_ADDRESS', '')),
-
associative array of email => name addresses:
'to' => [env('LOG_MAIL_ADDRESS', '') => 'Error'],`
-
array of email and name:
'to' => [ [ 'address' => env('LOG_MAIL_ADDRESS', ''), 'name' => 'Error', ], ],
SQL Query Logging
The last 10 SQL queries (with bindings and execution time) are automatically included in error emails.
To disable it:
'mail' => [ 'driver' => 'mail', 'log_queries' => false, // ... ],
Editor Links
File paths in error emails are clickable if you have configured the app.editor option in your Laravel application. Clicking a link will open the file at the correct line in your editor.
Laravel supports this natively since v9. Set it in config/app.php:
'editor' => 'phpstorm',
Or via environment variable:
APP_EDITOR=phpstorm
Supported editors: phpstorm, vscode, vscode-insiders, cursor, sublime, textmate, atom, nova, idea.
You can also use a custom URL scheme:
'editor' => [ 'href' => 'custom://open?file={file}&line={line}', ],
For remote servers where file paths differ from your local machine, use base_path to remap:
'editor' => [ 'name' => 'phpstorm', 'base_path' => '/local/path/to/project', ],
Upgrading
From v2 to v3
v3 completely redesigns the email output. The HTML format has changed and the HtmlFormatter::addRow() method has been removed.
v3 requires PHP 8.1+ and Laravel 10+. For older versions, use v2.
If you extended HtmlFormatter or relied on the HTML structure for parsing/filtering, review the new output format. The configuration API is unchanged — no config changes needed.
