PHPackages                             thephpx/laravel-error-mailer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. thephpx/laravel-error-mailer

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

thephpx/laravel-error-mailer
============================

A Laravel package that automatically emails 500-level error traces to a configured email address.

00PHP

Since Feb 23Pushed 4mo agoCompare

[ Source](https://github.com/thephpx/laravel-error-mailer)[ Packagist](https://packagist.org/packages/thephpx/laravel-error-mailer)[ RSS](/packages/thephpx-laravel-error-mailer/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Error Mailer
====================

[](#laravel-error-mailer)

[![Latest Version](https://camo.githubusercontent.com/fafd0f7bcd5b78a49db4dc25c40e0588dea002ac39f83554974ef80f08dff8ff/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746865706870782f6c61726176656c2d6572726f722d6d61696c65722e737667)](https://packagist.org/packages/thephpx/laravel-error-mailer)[![PHP Version](https://camo.githubusercontent.com/cc9cdea9aa96b40a822425e981b0a030e3371202973c7d57b74e8e99834f81dc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e312d626c7565)](https://php.net)[![Laravel](https://camo.githubusercontent.com/9bae2d9be2f5ba784143b82eae0b083e86e830cdaa9e751e8205adb30d882814/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d3130253230253743253230313125323025374325323031322d726564)](https://laravel.com)[![License](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](LICENSE)

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
--------

[](#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](https://github.com/orchestral/testbench)

---

Requirements
------------

[](#requirements)

PackageVersionPHP^8.1Laravel^10.0 | ^11.0 | ^12.0---

Installation
------------

[](#installation)

### 1. Install via Composer

[](#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`

[](#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

[](#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

[](#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
-----------------------

[](#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
------------

[](#how-it-works)

The package hooks into Laravel's **exception reporter** using `ExceptionHandler::reportable()`.
When an exception is thrown:

1. The package checks if it is **enabled**.
2. It checks the exception is **not in the ignored list**.
3. It resolves the **HTTP status code** — non-HTTP exceptions are treated as `500`.
4. It checks whether the status code is in `http_status_codes`.
5. It checks the **throttle cache** — same exception within the cooldown window is skipped.
6. 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
-------------

[](#email-preview)

The email includes:

SectionDetails**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
-------------

[](#running-tests)

```
composer install
./vendor/bin/phpunit
```

---

Changelog
---------

[](#changelog)

### v1.0.0

[](#v100)

- Initial release

---

License
-------

[](#license)

MIT © thephpx (Faisal Ahmed)

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance52

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity12

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/812660?v=4)[faisal ahmed](/maintainers/thephpx)[@thephpx](https://github.com/thephpx)

---

Top Contributors

[![thephpx](https://avatars.githubusercontent.com/u/812660?v=4)](https://github.com/thephpx "thephpx (4 commits)")

### Embed Badge

![Health badge](/badges/thephpx-laravel-error-mailer/health.svg)

```
[![Health](https://phpackages.com/badges/thephpx-laravel-error-mailer/health.svg)](https://phpackages.com/packages/thephpx-laravel-error-mailer)
```

###  Alternatives

[psr/log

Common interface for logging libraries

10.4k1.2B11.5k](/packages/psr-log)[open-telemetry/api

API for OpenTelemetry PHP.

1941.5M276](/packages/open-telemetry-api)[open-telemetry/sdk

SDK for OpenTelemetry PHP.

2328.5M343](/packages/open-telemetry-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
