thephpx/laravel-error-mailer
Composer 安装命令:
composer require thephpx/laravel-error-mailer
包简介
A Laravel package that automatically emails 500-level error traces to a configured email address.
README 文档
README
A zero-hassle Laravel package that automatically emails 500-level error stack traces to a configured address every time an unhandled server error occurs. No more checking logs manually.
Features
- 📧 Sends a beautifully formatted error email on 500-level exceptions
- 🔧 Fully configurable via
.env— no code changes required - 🔒 Masks sensitive input (
password,token,api_key, etc.) before sending - 🚦 Throttle support — prevents email flooding for repeated identical errors
- 🚫 Ignore list — skip certain exception classes you don't care about
- 📋 Includes full request context: URL, method, IP, headers, and input
- 🎨 Dark-themed professional HTML email template
- ✅ Laravel auto-discovery (zero manual registration)
- 🧪 Fully tested with Orchestra Testbench
Requirements
| Package | Version |
|---|---|
| PHP | ^8.1 |
| Laravel | ^10.0 | ^11.0 | ^12.0 |
Installation
1. Install via Composer
composer require thephpx/laravel-error-mailer
Laravel will auto-discover the service provider. No manual registration needed.
2. Set environment variables in .env
# ─── Required ──────────────────────────────────── # Email address to receive error notifications ERROR_MAILER_TO=admin@your-domain.com # ─── Optional (with defaults) ──────────────────── ERROR_MAILER_TO_NAME="Site Administrator" ERROR_MAILER_FROM=no-reply@your-domain.com ERROR_MAILER_FROM_NAME="Laravel Error Mailer" ERROR_MAILER_SUBJECT="[Error] :app_name — :exception_class" ERROR_MAILER_ENABLED=true # Cooldown (minutes) before the same error is emailed again (0 = off) ERROR_MAILER_THROTTLE=5 # Include request URL / method / IP / headers / input in the email? ERROR_MAILER_INCLUDE_REQUEST=true
That's it. The package is now active and will email errors automatically.
3. (Optional) Publish the config
php artisan vendor:publish --tag=error-mailer-config
This copies config/error-mailer.php to your application for full customisation.
4. (Optional) Publish the email view
php artisan vendor:publish --tag=error-mailer-views
This copies the Blade template to resources/views/vendor/error-mailer/ so you can customise the email layout.
Configuration Reference
After publishing, open config/error-mailer.php:
return [ // Master on/off switch 'enabled' => env('ERROR_MAILER_ENABLED', true), // Recipient 'to' => env('ERROR_MAILER_TO', null), 'to_name' => env('ERROR_MAILER_TO_NAME', 'Site Administrator'), // Sender (falls back to MAIL_FROM_* values) 'from' => env('ERROR_MAILER_FROM', env('MAIL_FROM_ADDRESS')), 'from_name' => env('ERROR_MAILER_FROM_NAME', env('MAIL_FROM_NAME')), // Subject line — use :app_name, :app_env, :exception_class as placeholders 'subject' => env('ERROR_MAILER_SUBJECT', '[Error] :app_name — :exception_class'), // Which HTTP status codes trigger an email (empty = ALL exceptions) 'http_status_codes' => [500, 502, 503, 504], // Exception classes to never email 'ignored_exceptions' => [], // Include request details in the email? 'include_request' => env('ERROR_MAILER_INCLUDE_REQUEST', true), // Input keys that will be replaced with ***REDACTED*** in the email 'sensitive_keys' => ['password', 'password_confirmation', 'token', 'secret', 'api_key'], // Throttle: same exception won't be emailed more than once per N minutes 'throttle_minutes' => env('ERROR_MAILER_THROTTLE', 5), ];
How It Works
The package hooks into Laravel's exception reporter using ExceptionHandler::reportable().
When an exception is thrown:
- The package checks if it is enabled.
- It checks the exception is not in the ignored list.
- It resolves the HTTP status code — non-HTTP exceptions are treated as
500. - It checks whether the status code is in
http_status_codes. - It checks the throttle cache — same exception within the cooldown window is skipped.
- It composes a safe email (redacting sensitive keys) and sends it via your configured mail driver.
All of this runs inside a try/catch so the mailer never crashes your application.
Email Preview
The email includes:
| Section | Details |
|---|---|
| Exception class | Full class name |
| Message | Exception message |
| Location | File path + line number |
| Stack trace | Full PHP stack trace |
| Request details | URL, method, IP, headers, input (with sensitive keys redacted) |
Running Tests
composer install ./vendor/bin/phpunit
Changelog
v1.0.0
- Initial release
License
MIT © thephpx (Faisal Ahmed)
thephpx/laravel-error-mailer 适用场景与选型建议
thephpx/laravel-error-mailer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「mailer」 「exception」 「error」 「notification」 「laravel」 「500」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 thephpx/laravel-error-mailer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 thephpx/laravel-error-mailer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 thephpx/laravel-error-mailer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Creates new sare mail transport for laravel applications
PHP Error Handler module that captures and displays all throwable errors in a given format, making debugging easier and more efficient
Error and Exception override and observers.
Error handler based on Booboo with HTML and JSON support
Error Share App, for handle error page
Mandrill Api Integration for Yii2
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 32
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-23