PHPackages                             xammie/mailbook - 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. xammie/mailbook

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

xammie/mailbook
===============

Laravel Mail Explorer

1.11.0(1mo ago)482458.3k—3.3%221MITPHPPHP ^8.0CI passing

Since Jul 7Pushed 4mo ago5 watchersCompare

[ Source](https://github.com/Xammie/mailbook)[ Packagist](https://packagist.org/packages/xammie/mailbook)[ Docs](https://github.com/xammie/mailbook)[ GitHub Sponsors](https://github.com/xammie)[ RSS](/packages/xammie-mailbook/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (32)Versions (34)Used By (1)

Mailbook
========

[](#mailbook)

[![Latest Version on Packagist](https://camo.githubusercontent.com/4c346545be799ce1e12b78a6ccc008ef20fbe3f7ff4b9c4662518966675b7102/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f78616d6d69652f6d61696c626f6f6b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/xammie/mailbook)[![GitHub Tests Action Status](https://camo.githubusercontent.com/1349e9d85700fa65bbc2a07f1e278962380f28e6a20a44157fdd6d61fb424c60/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f78616d6d69652f6d61696c626f6f6b2f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/xammie/mailbook/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/f5c71c44d1b996aba90ef3b583862be06518c49f53aa01d82df9637d95f09518/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f78616d6d69652f6d61696c626f6f6b2f70696e742e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/xammie/mailbook/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/cd41a27dfc90831a55dcb0f233bfa04cdafee14d8cf472cec26778980eb62d84/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f78616d6d69652f6d61696c626f6f6b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/xammie/mailbook)

Mailbook is a Laravel package that lets you easily inspect your mails without having to actually trigger it in your application.

[![Example screenshot](./screenshot.png)](https://mailbook.dev)

[View demo](https://mailbook.dev/)

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

[](#installation)

You can install the package via composer:

```
composer require --dev xammie/mailbook
```

Next install mailbook into your application

```
php artisan mailbook:install
```

Usage
-----

[](#usage)

The `mailbook:install` command will create a route file named `routes/mailbook.php`. In this file you can register your emails.

```
// This will use dependency injection if your mailable has parameters
Mailbook::add(VerificationMail::class);

// Use a closure to customize the parameters of the mail instance
Mailbook::add(function (): VerificationMail {
    $user = User::factory()->make();

    return new VerificationMail($user, '/example/url')
});
```

Next head over to `/mailbook` to preview the mailables.

Registering mails
-----------------

[](#registering-mails)

You can both register mailables that live in `App\Mails` and email notifications in `App\Notifications`.

```
// Mailable
Mailbook::add(VerificationMail::class);

// Notification
Mailbook::add(InvoiceCreatedNotification::class);
```

You can also use dependency injection in the closure.

```
// With dependency injection
Mailbook::add(function (VerificationService $verificationService): VerificationMail {
    return new VerificationMail($verificationService, '/example/url');
});

// Without dependency injection
Mailbook::add(function (): VerificationMail {
    $verificationService = app(VerificationService::class);

    return new VerificationMail($verificationService, '/example/url');
});
```

Sending to a user
-----------------

[](#sending-to-a-user)

A notification will most of the time need a user (also called `notifiable` in the notification class). You can set the desired user with the `::to()` method.

```
$user = User::factory()->create();

Mailbook::to($user)->add(WelcomeNotification::class);
```

If you don't need a user you can also pass an e-mail address.

```
Mailbook::to('example@mailbook.dev')->add(WelcomeNotification::class)
```

Grouping multiple mails
-----------------------

[](#grouping-multiple-mails)

You can group multiple mails under the same category. This can be done using the `category()` and `group()` methods.

```
Mailbook::category('Invoices')->group(function () {
    Mailbook::add(InvoiceCreatedNotification::class);
    Mailbook::add(InvoicePaidNotification::class);
});
```

To avoid having to pass the same `to()` to every mailable that needs it you can also use the `group()` method. This will use the notifiable to every mailable inside the group.

```
Mailbook::to('example@mailbook.dev')->group(function () {
    Mailbook::add(WelcomeNotification::class);
    Mailbook::add(TrialEndedNotification::class);
});
```

It is also possible to chain both `category()` and `to()` to the same group.

```
Mailbook::to('example@mailbook.dev')
    ->category('Invoices')
    ->group(function () {
        // ...
    });
```

Variants
--------

[](#variants)

When creating mails you might have a couple of different scenario's that you want to test for one mail, you can use variants to solve this.

```
// Use a closure to customize the parameters of the mail instance
Mailbook::add(OrderCreatedMail::class)
    ->variant('1 item', fn () => new OrderCreatedMail(Order::factory()->withOneProduct()->create()))
    ->variant('2 items', fn () => new OrderCreatedMail(Order::factory()->withTwoProducts()->create()));
```

Localization
------------

[](#localization)

When your application supports multiple languages you need to easily preview your mails in these languages. To enable this feature you have to add the following code to the `mailbook.php` config file.

```
'locales' => [
    'en' => 'English',
    'nl' => 'Dutch',
    'de' => 'German',
    'es' => 'Spanish'
],
```

This will display a dropdown in mailbook which you can use to switch to a different language.

[![Localization](./docs/localization.png)](./docs/localization.png)

Using the database
------------------

[](#using-the-database)

Most of the time your mailables will need database models. Sometimes you will even preform queries when rendering these mailables. Mailbook can automatically rollback database changes after rendering. You can enable it in the config with.

```
'database_rollback' => true,
```

You can now safely use factories and other queries when registering your mailables.

```
// All database changes are rolled back after rendering the mail.
Mailbook::add(function (): OrderShippedMail {
    $order = Order::factory()->create();
    $tracker = Tracker::factory()->create();

    return new OrderShippedMail($order, $tracker);
});
```

Database rollback is disabled by default.

Sending Mails
-------------

[](#sending-mails)

Testing your mails outside the browser is important if you want to make sure that everything is displayed correctly. You can use Mailbook to send mails to an email address of your choice using your default mail driver. This will show a button in the top-right corner which when pressed will send the currently selected email to the specified address. You can enable this in the config:

```
'send' => true,
'send_to' => 'test@mailbook.dev',
```

Customization
-------------

[](#customization)

You can publish the config file with:

```
php artisan vendor:publish --tag="mailbook-config"
```

Optionally, you can publish the views using

```
php artisan vendor:publish --tag="mailbook-views"
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](https://github.com/Xammie/mailbook/blob/main/CHANGELOG.md) for more information on what has changed recently.

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

[](#security-vulnerabilities)

Please review [our security policy](https://github.com/Xammie/mailbook/security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Max Hoogenbosch](https://github.com/Xammie)
- [All Contributors](https://github.com/Xammie/mailbook/contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/Xammie/mailbook/blob/main/LICENSE.md) for more information.

###  Health Score

60

—

FairBetter than 99% of packages

Maintenance80

Actively maintained with recent releases

Popularity57

Moderate usage in the ecosystem

Community24

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 74.6% 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.

###  Release Activity

Cadence

Every ~43 days

Recently: every ~107 days

Total

32

Last Release

53d ago

Major Versions

0.0.9 → 1.0.02022-08-26

PHP version history (3 changes)0.0.1PHP ^8.1

0.0.3PHP ^8.0|^8.1

1.7.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/168b78236005937dc3b1a91c321b92a32467601eeaa785cceb7a9b647cff40e5?d=identicon)[Xammie](/maintainers/Xammie)

---

Top Contributors

[![Xammie](https://avatars.githubusercontent.com/u/13081809?v=4)](https://github.com/Xammie "Xammie (341 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (51 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (45 commits)")[![AJenbo](https://avatars.githubusercontent.com/u/204594?v=4)](https://github.com/AJenbo "AJenbo (11 commits)")[![ItsRD](https://avatars.githubusercontent.com/u/4502205?v=4)](https://github.com/ItsRD "ItsRD (3 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (2 commits)")[![mstaack](https://avatars.githubusercontent.com/u/10169509?v=4)](https://github.com/mstaack "mstaack (2 commits)")[![niboko](https://avatars.githubusercontent.com/u/70974700?v=4)](https://github.com/niboko "niboko (1 commits)")[![daniel-de-wit](https://avatars.githubusercontent.com/u/3015394?v=4)](https://github.com/daniel-de-wit "daniel-de-wit (1 commits)")

---

Tags

laravelmailphpstorybooktailwindcsslaravelXammiemailbook

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/xammie-mailbook/health.svg)

```
[![Health](https://phpackages.com/badges/xammie-mailbook/health.svg)](https://phpackages.com/packages/xammie-mailbook)
```

###  Alternatives

[vormkracht10/laravel-mails

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

24149.7k](/packages/vormkracht10-laravel-mails)[spatie/laravel-notification-log

Log notifications sent by your Laravel app

207902.8k](/packages/spatie-laravel-notification-log)[wnx/laravel-sends

Keep track of outgoing emails in your Laravel application.

200427.3k](/packages/wnx-laravel-sends)[spatie/laravel-discord-alerts

Send a message to Discord

151408.0k](/packages/spatie-laravel-discord-alerts)[backstage/laravel-mails

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

24157.5k5](/packages/backstage-laravel-mails)[spatie/laravel-mailcoach-sdk

An SDK to easily work with the Mailcoach API in Laravel apps

41290.2k1](/packages/spatie-laravel-mailcoach-sdk)

PHPackages © 2026

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