定制 artryazanov/laravel-error-mailer 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

artryazanov/laravel-error-mailer

Composer 安装命令:

composer require artryazanov/laravel-error-mailer

包简介

A Laravel package for sending detailed error information via email.

README 文档

README

Latest Version on Packagist Tests Lint Codecov Total Downloads License

Laravel 11-13 package to automatically send detailed exception reports to configured email addresses. Features a beautiful HTML template with full stack traces, request data, and built-in rate limiting to prevent spamming your inbox when your application throws repeated errors.

📋 Requirements

  • PHP 8.2+
  • Laravel 11.x–13.x

📦 Installation

You can install the package via composer:

composer require artryazanov/laravel-error-mailer

Laravel auto-discovers the service provider. No manual registration is needed.

⚙️ Configuration

Publish the configuration and view files to customize them:

php artisan vendor:publish --tag="error-mailer-config"
php artisan vendor:publish --tag="error-mailer-views"

Configuration file: config/error-mailer.php

In your .env file, you can set the following variables:

ERROR_MAILER_ENABLED=true
ERROR_MAILER_FROM=error-mailer@example.com
ERROR_MAILER_TO=admin@example.com
ERROR_MAILER_CC=
ERROR_MAILER_BCC=
ERROR_MAILER_SUBJECT="Error on production"

# Rate limit: Max emails to send per time window (in seconds)
ERROR_MAILER_LIMIT=15
ERROR_MAILER_WINDOW=3600

💻 Usage

Laravel 11+

In newer Laravel versions, exception handling is configured in bootstrap/app.php. Add the explicit reporting callback inside your withExceptions method:

use Artryazanov\ErrorMailer\Facades\ErrorMailer;
use Illuminate\Foundation\Configuration\Exceptions;
use Throwable;

return Application::configure(basePath: dirname(__DIR__))
    // ...
    ->withExceptions(function (Exceptions $exceptions) {
        $exceptions->reportable(function (Throwable $e) {
            ErrorMailer::handle($e);
        });
    })->create();

Older Laravel Versions (or custom Handlers)

If you are using app/Exceptions/Handler.php, you can call the facade in your register method:

use Artryazanov\ErrorMailer\Facades\ErrorMailer;
use Throwable;

public function register(): void
{
    $this->reportable(function (Throwable $e) {
        ErrorMailer::handle($e);
    });
}

🛡️ Rate Limiting

If your application loses connection to a database or a critical service goes down, it might throw hundreds of exceptions per minute.

This package has built-in Rate Limiting to protect your inbox. By default, it allows sending 15 emails per hour. Any exceptions thrown beyond this limit will be suppressed from the mailer (but a standard Laravel Log::warning will be recorded stating that the email was suppressed).

You can tweak the threshold in your .env using ERROR_MAILER_LIMIT and ERROR_MAILER_WINDOW.

🎨 Customizing the View

If you published the views, you can find the HTML email template in resources/views/vendor/error-mailer/emails/exception.blade.php. You can modify it to match your company's branding, adjust the layout, or include additional variables.

📄 License

This package is released under the MIT License. See LICENSE for details.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-07-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固