PHPackages                             abrigham/laravel-email-exceptions - 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. [Mail &amp; Notifications](/categories/mail)
4. /
5. abrigham/laravel-email-exceptions

AbandonedLibrary[Mail &amp; Notifications](/categories/mail)

abrigham/laravel-email-exceptions
=================================

Email Exceptions from your laravel application

4.0(5y ago)3575.0k↓20.5%17[3 PRs](https://github.com/abrigham1/laravel-email-exceptions/pulls)MITPHPPHP ^7.2|^8.0CI failing

Since Jan 21Pushed 3y ago1 watchersCompare

[ Source](https://github.com/abrigham1/laravel-email-exceptions)[ Packagist](https://packagist.org/packages/abrigham/laravel-email-exceptions)[ RSS](/packages/abrigham-laravel-email-exceptions/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (5)Versions (15)Used By (0)

Laravel 7.x Email Exceptions
============================

[](#laravel-7x-email-exceptions)

[![Build Status](https://camo.githubusercontent.com/60098eff33893c0425cb097f7015ff092c66663a83bf6bf6b26391c8765627cd/68747470733a2f2f6170692e7472617669732d63692e6f72672f616272696768616d312f6c61726176656c2d656d61696c2d657863657074696f6e732e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/abrigham1/laravel-email-exceptions)[![Coverage Status](https://camo.githubusercontent.com/6197bd7b56548d09c2a09def1b8bf1e0592dbf5b2e559ca16220b53e5f385bfa/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f616272696768616d312f6c61726176656c2d656d61696c2d657863657074696f6e732f6d61737465722e737667)](https://codecov.io/github/abrigham1/laravel-email-exceptions?branch=master)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE.txt)

The Laravel 5 Email Exceptions package, based on this excellent cakephp package (), is designed to give developers an easy way to email debug information to themselves whenever an exception is thrown in their application. Information provided by default is:

- Environment
- Exception/Error Url
- Exception/Error Class
- Exception/Error Message
- Exception/Error Code
- File and Line Number
- Stack Trace

[![Screenshot](https://cloud.githubusercontent.com/assets/7387512/22176626/047ac836-dfdd-11e6-9a91-bb99b98333ac.png)](https://cloud.githubusercontent.com/assets/7387512/22176626/047ac836-dfdd-11e6-9a91-bb99b98333ac.png)

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Configuration](#configuration)
- [Basic Usage](#basic-usage)
    - [Basic Config](#basic-config)
    - [Throttling](#throttling)
    - [Global Throttling](#global-throttling)
- [Advanced Usage](#advanced-usage)
    - [Changing the view](#changing-the-view)
    - [Adding Arbitrary don't email logic](#adding-arbitrary-dont-email-logic)
- [Gotchas](#gotchas)
- [Bugs and Feedback](#bugs-and-feedback)
- [License](#license)

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

[](#installation)

You can install this plugin into your laravel 5.x application using [composer](http://getcomposer.org).

Run the following command

```
composer require abrigham/laravel-email-exceptions
```

After updating composer, add the service provider to the providers array in config/app.php

> If you are in laravel &gt;= 5.5 you can skip adding the provider to config/app.php as it will be auto-discovered

```
Abrigham\LaravelEmailExceptions\EmailExceptionsServiceProvider::class,
```

Then in app/Exceptions/Handler.php replace

```
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
```

with

```
use Abrigham\LaravelEmailExceptions\Exceptions\EmailHandler as ExceptionHandler;
```

Configuration
-------------

[](#configuration)

To publish the config file and view run the following command

```
php artisan vendor:publish --provider="Abrigham\LaravelEmailExceptions\EmailExceptionsServiceProvider"
```

That will create a config file for you in config/laravelEmailExceptions.php and a view in resources/views/vendor/laravelEmailExceptions/emailExceptions.blade.php

Default configuration:

```
'ErrorEmail' => [
    'email' => true,
    'dontEmail' => [],
    'throttle' => false,
    'throttleCacheDriver' => env('CACHE_DRIVER', 'file'),
    'throttleDurationMinutes' => 5,
    'dontThrottle' => [],
    'globalThrottle' => true,
    'globalThrottleLimit' => 20,
    'globalThrottleDurationMinutes' => 30,
    'toEmailAddress' => null,
    'fromEmailAddress' => null,
    'emailSubject' => null
]
```

- email (bool) - Enable or disable emailing of errors/exceptions
- dontEmail (array) - This works exactly like laravel's $dontReport variable documented here:  under Ignoring Exceptions By Type. Keep in mind also any exceptions under laravel's $dontReport also will not be emailed
- throttle (bool) - Enable or disable throttling of exception emails. Throttling is only performed if its been determined the exact same exception/error has already been emailed by checking the cache. Errors/Exceptions are determined to be unique by exception class + exception message + exception code
- throttleCacheDriver (string) - The cache driver to use for throttling, by default it uses CACHE\_DRIVER from your env file
- throttleDurationMinutes (int) - The duration in minutes of the throttle for example if you put 5 and a BadMethodCallException triggers an email if that same exception is thrown again it will not be emailed until 5 minutes have passed
- dontThrottle (array) - This is the same as dontEmail except provide a list of exceptions you do not wish to throttle ever even if throttling is turned on
- globalThrottle (bool) - Enable or disable whether you want to globally throttle the number of emails you can receive of all exception types by this application
- globalThrottleLimit (int) - The the maximum number of emails you want to receive in a given period.
- throttleDurationMinutes (int) - The duration in minutes of the global throttle for example if you put in 30 and have 10 for your globalThrottleLimit when the first email is sent out a 30 minute timer will commence once you reach the 10 email threshold no more emails will go out for that 30 minute period.
- toEmailAddress (string|array) - The email(s) to send the exceptions emails to such as the dev team
- fromEmailAddress (string) - The email address these emails should be sent from such as .
- emailSubject (string) - The subject of email, leave NULL to use default Default Subject: An Exception has been thrown on APP\_URL APP\_ENV

**Note:** the dontReport variable from **app/Exceptions/Handler.php** file will also not be emailed as it's assumed if they are not important enough to log then they also are not important enough to email

**Important:** You must fill out a toEmailAddress and fromEmailAddress or you will not receive emails.

Basic Usage
-----------

[](#basic-usage)

#### Basic Config

[](#basic-config)

Update your config values in **config/laravelEmailExceptions.php**

```
'ErrorEmail' => [
    'email' => true,
    'dontEmail' => [],
    'throttle' => true,
    'throttleCacheDriver' => env('CACHE_DRIVER', 'file'),
    'throttleDurationMinutes' => 5,
    'dontThrottle' => [],
    'globalThrottle' => true,
    'globalThrottleLimit' => 20,
    'globalThrottleDurationMinutes' => 30,
    'toEmailAddress' => 'dev@yoursite.com',
    'fromEmailAddress' => 'noreply@yoursite.com',
    'emailSubject' => null,
]
```

#### Throttling

[](#throttling)

Both throttling and global throttling are put in place in an attempt to prevent spam to the dev team. Throttling works by creating a unique cache key made from exception class + exception message + exception code. Its aim is to prevent duplicate exceptions from being reported via email giving the team time to fix them before they are reported again.

#### Global Throttling

[](#global-throttling)

Global throttling is a similar idea except it's put in place to prevent more then a certain number of emails going out within a given time period. This should typically only be necessary for an app wide failure ex major portions of the site are down so many varied types of exceptions are coming in from all directions.

Advanced Usage
--------------

[](#advanced-usage)

### Changing the view

[](#changing-the-view)

If you published your view using the command above you will be able to change the look of the exception email by modifying your view in **resources/views/vendor/laravelEmailExceptions/emailException.blade.php**

### Adding Arbitrary don't email logic

[](#adding-arbitrary-dont-email-logic)

If you need more complicated logic then just checking instanceof against the thrown exception there is a convenient hook for adding arbitrary logic to decide if an exception should be emailed.

In **app/Exceptions/Handler.php** implement the function appSpecificDontEmail(Exception $exception) ex.

```
