PHPackages                             dynamik-dev/laravel-mail-preview - 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. dynamik-dev/laravel-mail-preview

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

dynamik-dev/laravel-mail-preview
================================

A utility for viewing emails in your browser as you develop.

0.1.0(10mo ago)134[4 PRs](https://github.com/dynamik-dev/laravel-mail-preview/pulls)MITPHPPHP ^8.4CI passing

Since Jun 26Pushed 1mo agoCompare

[ Source](https://github.com/dynamik-dev/laravel-mail-preview)[ Packagist](https://packagist.org/packages/dynamik-dev/laravel-mail-preview)[ Docs](https://github.com/dynamik-dev/laravel-mail-preview)[ GitHub Sponsors](https://github.com/DynamikDev)[ RSS](/packages/dynamik-dev-laravel-mail-preview/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (14)Versions (7)Used By (0)

[![Laravel Mail Preview](./laravel-mail-preview.png)](./laravel-mail-preview.png)

[![Tests](https://github.com/dynamik-dev/laravel-mail-preview/actions/workflows/run-tests.yml/badge.svg)](https://github.com/dynamik-dev/laravel-mail-preview/actions/workflows/run-tests.yml)[![PHPStan](https://camo.githubusercontent.com/0729e562e10fac943b16dbb271b4af26488f779a33fc82cc3eef1e37a432c0b4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c253230352d627269676874677265656e2e737667)](https://phpstan.org/)[![BuyMeACoffee](https://raw.githubusercontent.com/pachadotdev/buymeacoffee-badges/main/bmc-yellow.svg)](https://buymeacoffee.com/chrisarter)

A utility for viewing emails in your browser as you develop with Laravel. This package allows you to preview your mailables without actually sending emails, making it easier to develop and test your email templates.

```
// Make any mailable previewable
class WelcomeEmail extends Mailable implements Previewable
{
    public static function toPreview(): self
    {
        return new self(User::factory()->make());
    }
}
```

Then, view it instantly at 👀 `http://your-app.test/mail/welcome-email`

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

[](#table-of-contents)

- [How to use](#how-to-use)
    - [1. Make Your Mailable Previewable](#1-make-your-mailable-previewable)
    - [2. View Your Email Preview](#2-view-your-email-preview)
    - [3. Custom Preview Slugs](#3-custom-preview-slugs)
- [Installation](#installation)
- [Requirements](#requirements)
- [Configuration](#configuration)
    - [Environment Variables](#environment-variables)
- [Security](#security)
- [Testing](#testing)
- [Contributing](#contributing)
- [Credits](#credits)
- [License](#license)

**Think of it like Factories for your emails.**

How to use
----------

[](#how-to-use)

### 1. Make Your Mailable Previewable

[](#1-make-your-mailable-previewable)

To make a mailable previewable, implement the `Previewable` interface and add the `toPreview()` method:

```
class WelcomeEmail extends Mailable implements Previewable
{
    public static function toPreview(): self
    {
        return new self(
            User::factory(['name' => 'Chris Arter'])->make()
        );
    }
}
```

### 2. View Your Email Preview

[](#2-view-your-email-preview)

Once you've made your mailable previewable, you can view it in your browser at:

```
http://your-app.test/mail/welcome-email

```

The URL slug is automatically generated from your class name:

- `WelcomeEmail` → `welcome-email`
- `OrderConfirmationMail` → `order-confirmation-mail`
- `TestMailable` → `test-mailable`

### 3. Custom Preview Slugs

[](#3-custom-preview-slugs)

You can also define a custom preview slug by adding a static property to your mailable:

```
class WelcomeEmail extends Mailable implements Previewable
{
    public static string $previewSlug = 'welcome';

    // ... rest of your mailable code
}
```

Now you can access it at: `http://your-app.test/mail/welcome`

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

[](#installation)

You can install the package via Composer:

```
composer require dynamik-dev/laravel-mail-preview --dev
```

The package will automatically register itself with Laravel.

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

[](#requirements)

- PHP 8.4+
- Laravel 10.x, 11.x, or 12.x

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

[](#configuration)

Publish the configuration file:

```
php artisan vendor:publish --provider="DynamikDev\MailPreview\MailPreviewServiceProvider"
```

This will create a `config/mail-preview.php` file with the following options:

```
return [
    // Enable or disable the mail preview
    'enabled' => env('MAIL_PREVIEW_ENABLED', false),

    // The route prefix for the mail preview
    'route_prefix' => env('MAIL_PREVIEW_ROUTE_PREFIX', 'mail'),

    // The path to discover mailables in
    'discover_path' => env('MAIL_PREVIEW_DISCOVER_PATH', base_path('app')),
];
```

### Environment Variables

[](#environment-variables)

To enable the mail preview, set `MAIL_PREVIEW_ENABLED` to `true` in your `.env` file.

These are the available options:

```
MAIL_PREVIEW_ENABLED=true
MAIL_PREVIEW_ROUTE_PREFIX=mail
MAIL_PREVIEW_DISCOVER_PATH=/path/to/your/app
```

Security
--------

[](#security)

**Important**: This package should only be enabled in development environments. The mail preview routes expose your email templates and could potentially leak sensitive information.

Make sure to:

1. Set `MAIL_PREVIEW_ENABLED=false` in production
2. Add the preview routes to your middleware if needed
3. Consider using authentication middleware for the preview routes

Testing
-------

[](#testing)

Run the test suite:

```
composer test
```

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

[](#contributing)

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

Credits
-------

[](#credits)

- [Chris Arter](https://github.com/christopherarter)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance75

Regular maintenance activity

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

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

Unknown

Total

1

Last Release

320d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/990cfbdeab8ba6fd8c12d682db3e9723e22350bb8b377d91d692927f3e195241?d=identicon)[christopherarter](/maintainers/christopherarter)

---

Top Contributors

[![christopherarter](https://avatars.githubusercontent.com/u/12786153?v=4)](https://github.com/christopherarter "christopherarter (7 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (2 commits)")

---

Tags

laravelDynamikDevlaravel-mail-preview

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/dynamik-dev-laravel-mail-preview/health.svg)

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

###  Alternatives

[spatie/laravel-data

Create unified resources and data transfer objects

1.7k28.9M627](/packages/spatie-laravel-data)[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)[xammie/mailbook

Laravel Mail Explorer

482458.3k1](/packages/xammie-mailbook)[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)

PHPackages © 2026

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