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

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

codeldev/laravel-mail-log
=========================

Record when mail is sent from your application

1.0.0(1mo ago)045↓100%[1 PRs](https://github.com/codeldev/laravel-mail-log/pulls)MITPHPPHP ^8.4CI passing

Since Apr 13Pushed 1mo agoCompare

[ Source](https://github.com/codeldev/laravel-mail-log)[ Packagist](https://packagist.org/packages/codeldev/laravel-mail-log)[ Docs](https://github.com/codeldev/laravel-mail-log)[ GitHub Sponsors](https://github.com/CodelDev)[ RSS](/packages/codeldev-laravel-mail-log/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (18)Versions (4)Used By (0)

Laravel Mail Log
================

[](#laravel-mail-log)

[![Latest Version on Packagist](https://camo.githubusercontent.com/d2255e4d4ab0a56851c4cb8602b2f9de638c86893d1c8e3409fcfcab181efd14/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f64656c6465762f6c61726176656c2d6d61696c2d6c6f672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/codeldev/laravel-mail-log)[![GitHub Tests Action Status](https://camo.githubusercontent.com/d6e7a14b27753d8b707c44cb6bb7610f5462454b8d2f1c3b9e03e31f841b2334/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f636f64656c6465762f6c61726176656c2d6d61696c2d6c6f672f72756e2d74657374732e796d6c3f6272616e63683d6d6173746572266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/codeldev/laravel-mail-log/actions?query=workflow%3Arun-tests+branch%3Amaster)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/2bed2809e5b8176371dba23ddb1bd2e3dc83c0777ca9d50cc824983b35ea8b9e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f636f64656c6465762f6c61726176656c2d6d61696c2d6c6f672f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d6173746572266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/codeldev/laravel-mail-log/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amaster)[![Total Downloads](https://camo.githubusercontent.com/db45f91ca382fc3078590199746f88538868baf2ac685385b01ddc89c0261bd1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f64656c6465762f6c61726176656c2d6d61696c2d6c6f672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/codeldev/laravel-mail-log)

A simple Laravel package that automatically logs every email sent by your application to the database. It listens to Laravel's built-in `MessageSending` event to record information without wrapping or modifying the mailer itself. Ships with configurable table names, a swappable Eloquent model, and a built-in prune command to manage retention.

---

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

[](#requirements)

- PHP 8.4+
- Laravel 13+

---

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

[](#installation)

You can install the package via composer:

```
composer require codeldev/laravel-mail-log
```

You can publish and run the migrations with:

```
php artisan vendor:publish --tag="mail-log-migrations"
php artisan migrate
```

You can publish the config file with:

```
php artisan vendor:publish --tag="mail-log-config"
```

This is the contents of the published config file:

```
return [
    'prune_days' => (int) env('MAIL_LOG_PRUNE_DAYS', 365),
    'model' => CodelDev\LaravelMailLog\Models\LaravelMailLog::class,
    'table' => env('MAIL_LOG_TABLE', 'mail_log'),
];
```

### Environment Variables

[](#environment-variables)

The following env variables are available to configure the package using your env file.

```
MAIL_LOG_PRUNE_DAYS=365
MAIL_LOG_TABLE=mail_log
```

---

Usage
-----

[](#usage)

Once installed, the package automatically logs every outgoing email. No additional setup is required.

### Pruning Old Records

[](#pruning-old-records)

Add to your `routes/console.php` file:

```
Schedule::command('mail-log:prune')
    ->weeklyOn(1, '02:30')
    ->withoutOverlapping();
```

Run manually:

```
php artisan mail-log:prune
```

---

Querying the Data
-----------------

[](#querying-the-data)

The package provides an Eloquent model you can use directly:

```
use CodelDev\LaravelMailLog\Models\LaravelMailLog;

// Get all logged emails
$emails = LaravelMailLog::all();

// Get emails sent to a specific address (not available for SQLite)
$emails = LaravelMailLog::query()
    ->whereJsonContains('to', 'user@example.com')
    ->latest()
    ->get();

// Get emails sent today
$emails = LaravelMailLog::query()
    ->whereDate('created_at', today())
    ->get();

// Search by subject
$emails = LaravelMailLog::query()
    ->where('subject', 'like', '%Welcome%')
    ->latest()
    ->get();
```

---

### Available Fields

[](#available-fields)

**LaravelMailLog**

FieldType`id``string` (UUID)`from``string|null``to``array|null``cc``array|null``bcc``array|null``subject``string``body``string``headers``string|null``attachments``array|null``created_at``CarbonImmutable``updated_at``CarbonImmutable`---

Using a Custom Model
--------------------

[](#using-a-custom-model)

You can extend the package model to add your own behaviour, scopes, or relationships. Create your custom model, extend the package model, then update the config:

```
use CodelDev\LaravelMailLog\Models\LaravelMailLog as BaseMailLog;

class MailLog extends BaseMailLog
{
    public function scopeToRecipient($query, string $email)
    {
        return $query->whereJsonContains('to', $email);
    }
}
```

Then in `config/mail-log.php`:

```
'model' => \App\Models\MailLog::class,
```

---

Testing
-------

[](#testing)

```
composer test
```

---

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

---

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

---

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

---

Credits
-------

[](#credits)

- [CodelDev](https://github.com/CodelDev)

---

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance91

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity53

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

57d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/179911763?v=4)[CodelDev](/maintainers/CodelDev)[@codeldev](https://github.com/codeldev)

---

Top Contributors

[![codeldev](https://avatars.githubusercontent.com/u/179911763?v=4)](https://github.com/codeldev "codeldev (1 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

laravellaravel-mail-logcodeldev

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/codeldev-laravel-mail-log/health.svg)

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

###  Alternatives

[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.3M41](/packages/spatie-laravel-pdf)[spatie/laravel-health

Monitor the health of a Laravel application

88011.3M149](/packages/spatie-laravel-health)[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24655.3k](/packages/vormkracht10-laravel-mails)[xammie/mailbook

Laravel Mail Explorer

482519.8k1](/packages/xammie-mailbook)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3913.7k](/packages/rawilk-profile-filament-plugin)[backstage/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24675.5k8](/packages/backstage-laravel-mails)

PHPackages © 2026

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