PHPackages                             yhw/laravel-email-database-log - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. yhw/laravel-email-database-log

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

yhw/laravel-email-database-log
==============================

A simple database logger for all outgoing emails sent by Laravel website - built from shvetsgroup/laravel-email-database-log.

v1.0.0(2y ago)072MITPHP

Since Nov 19Pushed 2y agoCompare

[ Source](https://github.com/stowe39/laravel-email-database-log)[ Packagist](https://packagist.org/packages/yhw/laravel-email-database-log)[ RSS](/packages/yhw-laravel-email-database-log/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

Laravel Email Database Log
==========================

[](#laravel-email-database-log)

A simple database logger for all outgoing emails sent by Laravel website. Forked from ShvetsGroup\\LaravelEmailDatabaseLog.

For Laravel 5.8 - use 2.\* versions

For Laravel 6 - use 3.\* versions

For Laravel 7 - use 4.\* versions

For Laravel 8 - use 5.\* versions

Version 5.1 is using Filesystems which is a breaking change from 5.3. See below for upgrade information.

Custom Templates
================

[](#custom-templates)

To make the email log integrate better with your laravel theme, set the path to your blade files, using the EMAIL\_LOG\_CUSTOM\_TEMPLATE option, in your .env file.

The blade files I use are in the custom\_templates folder.

In my project they are in resources\\views\\admin\\templates\\email\_logger\\

and my .env file has the lines:

```
EMAIL_LOG_ACCESS_MIDDLEWARE="admin"
EMAIL_LOG_ROUTES_PREFIX="admin"
EMAIL_LOG_CUSTOM_TEMPLATE="admin.templates.email_logger.email-logger"
```

Installation
============

[](#installation)

Step 1: Composer
----------------

[](#step-1-composer)

Laravel Email Database Log can be installed via [composer](http://getcomposer.org) by running this line in terminal:

```
composer require yhw/laravel-email-database-log
```

Step 2: Configuration
---------------------

[](#step-2-configuration)

You can skip this step if your version of Laravel is 5.5 or above. Otherwise, you have to add the following to your config/app.php in the providers array:

```
'providers' => [
    // ...
    Yhw\LaravelEmailDatabaseLog\LaravelEmailDatabaseLogServiceProvider::class,
],
```

Step 3: Migration
-----------------

[](#step-3-migration)

Now, run this in terminal:

```
php artisan migrate
```

Step 4: Config
--------------

[](#step-4-config)

To publish config file run this in terminal:

```
php artisan vendor:publish --provider="Yhw\LaravelEmailDatabaseLog\LaravelEmailDatabaseLogServiceProvider"
```

Config contains following parameters:

```
//name of the disk where the attachments will be saved
'disk' => env('EMAIL_LOG_DISK','email_log_attachments'),

//template override
'custom_template' => env('EMAIL_LOG_CUSTOM_TEMPLATE',null),

//to prevent access to list of logged emails through WEB routes add a middlewares
//multiple middlewares can be used (separate by comma)
'access_middleware' => env('EMAIL_LOG_ACCESS_MIDDLEWARE',null),

//to prevent access to list of logged emails through API routes add a middlewares
//multiple middlewares can be used (separate by comma)
'access_middleware_api' => env('EMAIL_LOG_ACCESS_MIDDLEWARE_API',null),

//this parameter prefixes the routes for listing of logged emails using WEB routes
'routes_prefix' => env('EMAIL_LOG_ROUTES_PREFIX',''),

//this parameter prefixes the routes for listing of logged emails using API routes
'routes_prefix_api' => env('EMAIL_LOG_ROUTES_PREFIX_API',''),

//custom route prefix for webhooks
'routes_webhook_prefix' => env('EMAIL_LOG_ROUTES_WEBHOOK_PREFIX', env('EMAIL_LOG_ROUTES_PREFIX','')),

//mailgun secret and whether to ommit events for emails which were not found
'mailgun' => [
    'secret' => env('MAILGUN_SECRET', null),
    'filter_unknown_emails' => env('EMAIL_LOG_MAILGUN_FILTER_UNKNOWN_EMAILS', true),
],
```

Usage
=====

[](#usage)

After installation, any email sent by your website will be logged to `email_log` table in the site's database.

Any attachments will be saved in `storage/email_log_attachments` disk. The `email_log_attachments` can be changed by publishing the config file and changing the 'folder' value.

You also need to add the following disk in the `config/filesystems.php` file:

```
'email_log_attachments' => [
    'driver' => 'local',
    'root' => storage_path('app/email_log_attachments'),
],

```

If you want to process the logged email or save/format some additional data on your system you can hook up to the `Yhw\LaravelEmailDatabaseLog\LaravelEvents\EmailLogged` event via a Laravel listener:

Don't forget to register the event:

If you're using Laravel &gt;=5.8.9 you can use `Event Discovery` instead:

If using queues on your server you will need to restart the worker for the library to work:

```
Remember, queue workers are long-lived processes and store the booted application state in memory.
As a result, they will not notice changes in your code base after they have been started.
So, during your deployment process, be sure to restart your queue workers.

https://laravel.com/docs/5.5/queues#running-the-queue-worker

```

You can review sent emails using the following URI `/email-log`.

You can prefix this URI by adding something like `EMAIL_LOG_ROUTES_PREFIX=prefix/` to your .env file.

You can protect this URI using middleware by adding something like `EMAIL_LOG_ACCESS_MIDDLEWARE=auth,landlord` to your .env file.

MailGun webhooks
----------------

[](#mailgun-webhooks)

You can use Mailgun webhooks to log webhook events. In your MailGun Webhooks section add:

```
https://example.com/email-log/webhooks/event

```

for all of the events. If you used a `prefix` in the config file then this should be reflected in the url:

```
https://example.com/your-prefix/email-log/webhooks/event

```

Upgrade from 5.2.2 to 5.3.0 - API ENDPOINTS AVAILABLE, BREAKING CHANGE
----------------------------------------------------------------------

[](#upgrade-from-522-to-530---api-endpoints-available-breaking-change)

API ENDPOINTS AVAILABLE:

New routes with JSON responses:

```
https://example.com/api/your-prefix/email-log
https://example.com/api/your-prefix/email-log/{id}
https://example.com/api/your-prefix/email-log/{id}/attachment/{attachment}
https://example.com/api/your-prefix/email-log/delete

```

BREAKING CHANGE:

The logic for presentation of attachments (on single email view: `show.blade.php`) has been moved to backend. If you are not using the default `show.blade.php` and are displaying list of attachments you should reflect these changes in your code. Namely, you no need to check if the file exists or add the attachment to the route to access it. Instead the returned data will be array with of following formats (depending if file can be found on disk or not):

```
//file can be found
[
    'name' => 'filename.pdf',
    'route' => 'https://example.com/api/email-log/email-id/attachment/attachment-key',
]
//file can't be found
[
    'name' => 'filename.pdf',
    'message' => 'file not found',
]

```

Note following: `/api` part will be dropped in html response, `email-id` is the `id` of the email, `attachment-key` is the order of attachment starting at `0`.

Upgrade from 5.1.0 to 5.2.0 - BREAKING CHANGE
---------------------------------------------

[](#upgrade-from-510-to-520---breaking-change)

Add the following parameters to the end of the `config/email_log.php` array:

```
    ...

    'routes_webhook_prefix' => env('EMAIL_LOG_ROUTES_WEBHOOK_PREFIX', env('EMAIL_LOG_ROUTES_PREFIX','')),
    'mailgun' => [
        'secret' => env('MAILGUN_SECRET', null),
        'filter_unknown_emails' => env('EMAIL_LOG_MAILGUN_FILTER_UNKNOWN_EMAILS', true),
    ],

```

Upgrade from 5.0.3 to 5.1.0 - BREAKING CHANGE
---------------------------------------------

[](#upgrade-from-503-to-510---breaking-change)

IMPORTANT - please upgrade to 5.2.1 right away as there are some fixes for the 5.1.0 upgrade. I was hastly and missed some issues which are corrected in 5.2.1.

As email log attachments might quickly grow to large size you'd want to use some external storage to save them. To enable this we need to utilize the Laravel's Filesystem. Follow the guide below if you were using the 5.0.3 and wish to upgrade to 5.1.0.

Change a line in `config/email_log.php` file from:

```
'folder' => env('EMAIL_LOG_ATTACHMENT_FOLDER','email_log_attachments'),

```

to

```
'disk' => env('EMAIL_LOG_DISK','email_log_attachments'),

```

In `config/filesystems.php` add

```
'email_log_attachments' => [
    'driver' => 'local',
    'root' => storage_path('app/email_log_attachments'),
],

```

the `'root'` must point to the folder where you were previously saving the attachements.

You will also need to drop the current prefix from the `email_log.attachments` column (default was `email_log_attachments`). For example `email_log_attachments/12345678910/my_file.jpg` should be renamed to `12345678910/my_file.jpg`.

You can run following code using `php artisan tinker` to fix these issues. Depending on the amount of data, it could take some time to finish:

```
$log = Yhw\LaravelEmailDatabaseLog\EmailLog::where('attachments','!=', null)
$log->count()
$log->chunk(100, function($chunk) { foreach($chunk as $l) { $l->attachments = str_replace('email_log_attachments/', '', $l->attachments); $l->save(); } })

```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

905d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4a5a0c092b875cfd6d5ed5d0a42eb435fc6b42bf2f2c878aeac711033278d73e?d=identicon)[stowe39](/maintainers/stowe39)

---

Top Contributors

[![dmcbrn](https://avatars.githubusercontent.com/u/40859618?v=4)](https://github.com/dmcbrn "dmcbrn (58 commits)")[![dbr0](https://avatars.githubusercontent.com/u/13360206?v=4)](https://github.com/dbr0 "dbr0 (27 commits)")[![neochief](https://avatars.githubusercontent.com/u/121889?v=4)](https://github.com/neochief "neochief (21 commits)")[![kentdahl](https://avatars.githubusercontent.com/u/2970005?v=4)](https://github.com/kentdahl "kentdahl (5 commits)")[![stowe39](https://avatars.githubusercontent.com/u/100562043?v=4)](https://github.com/stowe39 "stowe39 (5 commits)")[![tsekka](https://avatars.githubusercontent.com/u/43533692?v=4)](https://github.com/tsekka "tsekka (3 commits)")[![juniorb2ss](https://avatars.githubusercontent.com/u/3980385?v=4)](https://github.com/juniorb2ss "juniorb2ss (3 commits)")[![arsenipachkovski](https://avatars.githubusercontent.com/u/26527192?v=4)](https://github.com/arsenipachkovski "arsenipachkovski (2 commits)")[![hapheus](https://avatars.githubusercontent.com/u/837072?v=4)](https://github.com/hapheus "hapheus (1 commits)")[![d-lamers](https://avatars.githubusercontent.com/u/3164508?v=4)](https://github.com/d-lamers "d-lamers (1 commits)")

---

Tags

laravelmarkdown

### Embed Badge

![Health badge](/badges/yhw-laravel-email-database-log/health.svg)

```
[![Health](https://phpackages.com/badges/yhw-laravel-email-database-log/health.svg)](https://phpackages.com/packages/yhw-laravel-email-database-log)
```

###  Alternatives

[flarum/core

Delightfully simple forum software.

211.3M1.9k](/packages/flarum-core)[dmcbrn/laravel-email-database-log

A simple database logger for all outgoing emails sent by Laravel website - built from shvetsgroup/laravel-email-database-log.

1633.6k](/packages/dmcbrn-laravel-email-database-log)[masterro/laravel-mail-viewer

Easily view in browser outgoing emails.

6392.1k](/packages/masterro-laravel-mail-viewer)[dniccum/nova-documentation

A Laravel Nova tool that allows you to add markdown-based documentation to your administrator's dashboard.

37116.4k](/packages/dniccum-nova-documentation)[shaffe/laravel-mail-log-channel

A package to support logging via email in Laravel

1286.2k](/packages/shaffe-laravel-mail-log-channel)[dragon-code/laravel-http-logger

Logging incoming HTTP requests

319.8k3](/packages/dragon-code-laravel-http-logger)

PHPackages © 2026

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