A powerful Filament plugin that provides instant error notifications via email and Discord webhooks, with a beautiful error details page for debugging. Never miss a critical error in your application again!
composer require hugomyb/filament-error-mailer
Publish the configuration file:
php artisan vendor:publish --tag="error-mailer-config"
This creates config/error-mailer.php with the following default configuration:
return [ 'email' => [ 'recipient' => ['recipient1@example.com'], 'bcc' => [], 'cc' => [], 'subject' => 'An error has occurred - ' . config('app.name'), ], 'disabledOn' => [ // ], 'cacheCooldown' => 10, // in minutes 'webhooks' => [ 'discord' => env('ERROR_MAILER_DISCORD_WEBHOOK'), 'message' => [ 'title' => 'Error Alert - ' . config('app.name'), 'description' => 'An error has occurred in the application.', 'error' => 'Error', 'file' => 'File', 'line' => 'Line', 'details_link' => 'See more details' ], ], 'storage_path' => storage_path('app/errors'), 'ignore' => [ 'levels' => [ // 'debug', // 'info', ], 'exceptions' => [ // \Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class, ], ],];
⚠️ IMPORTANT: Configure your mail server in
.envto receive email notifications:
MAIL_MAILER=smtpMAIL_HOST=your-smtp-host.comMAIL_PORT=587MAIL_USERNAME=your-smtp-usernameMAIL_PASSWORD=your-smtp-passwordMAIL_ENCRYPTION=tlsMAIL_FROM_ADDRESS=noreply@yourapp.comMAIL_FROM_NAME="${APP_NAME}"
Add the plugin to your Filament panel provider (e.g., app/Providers/Filament/AdminPanelProvider.php):
use Hugomyb\FilamentErrorMailer\FilamentErrorMailerPlugin; public function panel(Panel $panel): Panel{ return $panel // ... other configuration ->plugins([ FilamentErrorMailerPlugin::make(), ]);}
If you want to customize the error details page or email template:
php artisan vendor:publish --tag="error-mailer-views"
Configure email recipients and subject in config/error-mailer.php:
'email' => [ 'recipient' => ['admin@example.com', 'dev@example.com'], 'bcc' => ['monitoring@example.com'], 'cc' => [], 'subject' => 'Error Alert - ' . config('app.name'),],
Options:
recipient (array): Primary email addresses to receive notificationsbcc (array): Blind carbon copy recipientscc (array): Carbon copy recipientssubject (string): Email subject line (supports dynamic values)Send error notifications to Discord channels:
1. Create a Discord Webhook:
2. Add to .env:
ERROR_MAILER_DISCORD_WEBHOOK="https://discord.com/api/webhooks/your-webhook-id/your-webhook-token"
3. Customize webhook messages (optional):
'webhooks' => [ 'discord' => env('ERROR_MAILER_DISCORD_WEBHOOK'), 'message' => [ 'title' => 'Error Alert - ' . config('app.name'), 'description' => 'An error has occurred in the application.', 'error' => 'Error', 'file' => 'File', 'line' => 'Line', 'details_link' => 'View Details', ],],
Control which errors trigger notifications:
'ignore' => [ // Ignore specific log levels 'levels' => [ 'debug', 'info', // 'warning', // 'error', ], // Ignore specific exception types 'exceptions' => [ \Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class, \Illuminate\Validation\ValidationException::class, \Illuminate\Auth\AuthenticationException::class, ],],
Available log levels:
debug - Detailed debug informationinfo - Interesting eventsnotice - Normal but significant eventswarning - Exceptional occurrences that are not errorserror - Runtime errorscritical - Critical conditionsalert - Action must be taken immediatelyemergency - System is unusablePrevent notifications in certain environments (e.g., local development):
'disabledOn' => [ 'local', 'testing',],
Prevent notification spam for duplicate errors:
'cacheCooldown' => 10, // in minutes
If the same error occurs multiple times within this period, only the first occurrence will trigger a notification.
Customize where error JSON files are stored:
'storage_path' => storage_path('app/errors'),
When an error occurs, the package intelligently identifies the first line of code from your application (excluding vendor files) in the stack trace.
Example:
Instead of showing:
File: /vendor/laravel/framework/src/Illuminate/Database/Connection.phpLine: 742
You'll see:
Application File: /app/Http/Controllers/UserController.php ← Your code!Application Line: 25 ← Your code!Origin File: /vendor/laravel/framework/src/Illuminate/Database/Connection.phpOrigin Line: 742
This makes debugging significantly faster by immediately showing you where in your code the error originated.
Each error notification includes a unique link to a beautiful, feature-rich error details page:
Features:
Information displayed:
Access: Only authenticated Filament users can view error details.
The cooldown system prevents notification spam:
Error identification: Errors are identified by a hash of the error message and file path.
Error detail links are automatically included in:
URL format: https://yourapp.com/error-mailer/{errorId}
Example email:
Subject: Error Alert - MyApp An error has occurred:Message: Call to undefined method...File: /app/Http/Controllers/UserController.phpLine: 25 View full details: https://yourapp.com/error-mailer/abc123def456
Error JSON files are stored indefinitely by default. To prevent excessive storage usage, schedule a cleanup task in app/Console/Kernel.php:
protected function schedule(Schedule $schedule){ // Delete errors older than 3 months $schedule->call(function () { $storagePath = config('error-mailer.storage_path'); $files = File::files($storagePath); foreach ($files as $file) { if ($file->getMTime() < now()->subMonths(3)->timestamp) { File::delete($file->getRealPath()); } } })->daily();}
Recommended retention periods:
return [ // Email notification settings 'email' => [ 'recipient' => ['admin@example.com'], 'bcc' => [], 'cc' => [], 'subject' => 'Error Alert - ' . config('app.name'), ], // Environments where notifications are disabled 'disabledOn' => [ // 'local', // 'testing', ], // Cooldown period in minutes 'cacheCooldown' => 10, // Webhook configuration 'webhooks' => [ 'discord' => env('ERROR_MAILER_DISCORD_WEBHOOK'), 'message' => [ 'title' => 'Error Alert - ' . config('app.name'), 'description' => 'An error has occurred in the application.', 'error' => 'Error', 'file' => 'File', 'line' => 'Line', 'details_link' => 'View Details', ], ], // Storage path for error JSON files 'storage_path' => storage_path('app/errors'), // Error filtering 'ignore' => [ 'levels' => [ // 'debug', // 'info', ], 'exceptions' => [ // \Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class, ], ],];
This plugin is also available for Laravel projects without Filament:
Contributions are welcome! Please see CONTRIBUTING for details.
# Clone the repositorygit clone https://github.com/hugomyb/filament-error-mailer.gitcd filament-error-mailer # Install dependenciescomposer install # Run testscomposer test # Run tests with coveragecomposer test-coverage
# Run all testsvendor/bin/pest # Run specific test filevendor/bin/pest tests/Unit/ErrorDetailsBuilderTest.php # Run with coveragevendor/bin/pest --coverage
If you discover a security vulnerability, please send an email to hugomayonobe@gmail.com. All security vulnerabilities will be promptly addressed.
Please review our security policy for more information.
The MIT License (MIT). Please see License File for more information.
If you find this package helpful, please consider:
Made with ❤️ for the Filament community