PHPackages                             spatie/laravel-mailable-test - 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. spatie/laravel-mailable-test

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

spatie/laravel-mailable-test
============================

An artisan command to easily test a mailable

2.4.2(2mo ago)149241.8k↑29.2%141MITPHPPHP ^7.3|^8.0CI passing

Since Jan 28Pushed 2mo ago3 watchersCompare

[ Source](https://github.com/spatie/laravel-mailable-test)[ Packagist](https://packagist.org/packages/spatie/laravel-mailable-test)[ Docs](https://github.com/spatie/laravel-mailable-test)[ Fund](https://spatie.be/open-source/support-us)[ RSS](/packages/spatie-laravel-mailable-test/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (24)Used By (1)

An artisan command to easily test a mailable
============================================

[](#an-artisan-command-to-easily-test-a-mailable)

[![Latest Version on Packagist](https://camo.githubusercontent.com/54425482dd4dc041916fd13838633f192772346f53fea3c7d7f9127dbfd421cf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6c61726176656c2d6d61696c61626c652d746573742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-mailable-test)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![GitHub Workflow Status](https://camo.githubusercontent.com/59e353391ec9cdabaf678574d26d4ba5ed4733ad6035737113467213c613051b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7370617469652f6c61726176656c2d6d61696c61626c652d746573742f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473)](https://github.com/spatie/laravel-mailable-test/actions/workflows/run-tests.yml)[![Check & fix styling](https://github.com/spatie/laravel-mailable-test/workflows/Check%20&%20fix%20styling/badge.svg)](https://github.com/spatie/laravel-mailable-test/workflows/Check%20&%20fix%20styling/badge.svg)[![Total Downloads](https://camo.githubusercontent.com/ea3c4eec316c9234c18b5377aa134db5b5f4f3601f6fae77aa873ecb59933254/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6c61726176656c2d6d61696c61626c652d746573742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-mailable-test)

Do you have to fill out an entire form just to test a mail sent by your app? Or even worse, complete an entire checkout process to just view and debug an order confirmation mail? Stop. The. Madness.

This package provides an artisan command that can send a mailable to an email-address. It can be used like this:

```
php artisan mail:send-test "OrderConfirmation" recipient@mail.com
```

The given mailable will be sent to the given recipient. Any parameters handed to the `__construct` method of the mailable class will be automatically passed in.

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/c584d8a6461ac943d1488611fa6555014762860f690d0dbd49cc5f47be8ab441/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f6c61726176656c2d6d61696c61626c652d746573742e6a70673f743d31)](https://spatie.be/github-ad-click/laravel-mailable-test)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

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

[](#installation)

You can install the package via composer:

```
composer require spatie/laravel-mailable-test
```

The package will automatically register itself.

Optionally you can publish the config-file with:

```
php artisan vendor:publish --provider="Spatie\MailableTest\MailableTestServiceProvider" --tag="config"
```

This is the contents of the published config file:

```
return [

    /*
     * This class will be used to generate argument values for the constructor
     * of a mailable. This can be any class as long as it
     * extends \Spatie\MailableTest\ArgumentValueProvider::class
     */
    'argument_value_provider_class' => \Spatie\MailableTest\FakerArgumentValueProvider::class,

    /*
     * Base namespace Mailable classes
     */
    'base_namespace' => 'App\Mail',
];
```

Usage
-----

[](#usage)

To send any mailable issue this artisan command:

```
php artisan mail:send-test "App\Mail\MyMailable" recipient@mail.com
```

This will send the given mailable to the given mail-address. The to-, cc- and bcc-address that may be set in the given mailable will be cleared. The mail will only be sent to the mail-address given in the artisan command.

The package will provide a value for any typehinted argument of the constructor of the mailable. If a argument is a `int`, `string` or `bool` the package will generated a value using [Faker](https://github.com/FakerPHP/Faker). Any argument that typehints an Eloquent model will receive the first record of that model. For all arguments that have a class typehint an argument will be generated using the container.

Customizing the values passed to the mailable constructor
---------------------------------------------------------

[](#customizing-the-values-passed-to-the-mailable-constructor)

### Via the command

[](#via-the-command)

The easiest way to customize the values passed to the mailable constructor is to use the `values` option of the `mail:send-test` command. Image the constructor for your mailable looks like this:

```
public function __construct(string $title, Order $order)
{
   ...
}
```

The `Order` class in this example is an eloquent model. If you don't want the package to generate fake values or use the first `Order`, you can pass a `values` option to the command. The option should get a string with comma separated pair. The first value of each pair (separated by ':') should be the name of the argument in the mailable constructor. The second value should be the value that should be passed to that argument. For arguments concerning Eloquent models, the passed value will be used as the id.

So in this example `My title` will be passed to `$title` and an `Order` with id 5 will be passed to `$order`.

```
php artisan mail:send-test "App\Mail\OrderConfirmation" recipient@mail.com --values="title:My title,order:5"
```

### By overriding the `ArgumentValueProvider`

[](#by-overriding-the-argumentvalueprovider)

The class that is responsible for getting values that should be passed on to the mailable constructor is `Spatie\MailableTest\FakerArgumentValueProvider`. You can override this class by specifying your own class in the `argument_value_provider_class` in the `laravel-mailable-test` config file.

By default the package will pass the first record of an Eloquent model to each argument that typehints a model. If you want to use your factories instead, you can do this.

```
namespace App;

use Spatie\MailableTest\FakerArgumentValueProvider;

class MyCustomArgumentValueProvider extends FakerArgumentValueProvider
{
       protected function getModelInstance(string $mailableClass, string $argumentName, Model $model, $id): Model
       {
          return factory(get_class($model));
       }
}
```

Changelog
---------

[](#changelog)

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

Testing
-------

[](#testing)

```
$ composer test
```

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

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you've found a bug regarding security please mail  instead of using the issue tracker.

Postcardware
------------

[](#postcardware)

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.

We publish all received postcards [on our company website](https://spatie.be/en/opensource/postcards).

Credits
-------

[](#credits)

- [Freek Van der Herten](https://github.com/freekmurze)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

63

—

FairBetter than 99% of packages

Maintenance83

Actively maintained with recent releases

Popularity50

Moderate usage in the ecosystem

Community26

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 62% 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 ~157 days

Recently: every ~375 days

Total

22

Last Release

86d ago

Major Versions

0.0.2 → 1.0.02017-01-30

v1.x-dev → 2.0.02017-09-01

PHP version history (5 changes)0.0.1PHP ^7.0

2.0.3PHP ^7.1

2.2.0PHP ^7.2

2.2.3PHP ^7.2|^8.0

2.3.0PHP ^7.3|^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7535935?v=4)[Spatie](/maintainers/spatie)[@spatie](https://github.com/spatie)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (98 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (11 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (9 commits)")[![patinthehat](https://avatars.githubusercontent.com/u/5508707?v=4)](https://github.com/patinthehat "patinthehat (8 commits)")[![brendt](https://avatars.githubusercontent.com/u/6905297?v=4)](https://github.com/brendt "brendt (6 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (4 commits)")[![riasvdv](https://avatars.githubusercontent.com/u/3626559?v=4)](https://github.com/riasvdv "riasvdv (3 commits)")[![rubenvanassche](https://avatars.githubusercontent.com/u/619804?v=4)](https://github.com/rubenvanassche "rubenvanassche (3 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (2 commits)")[![oliverearl](https://avatars.githubusercontent.com/u/14837181?v=4)](https://github.com/oliverearl "oliverearl (2 commits)")[![akoepcke](https://avatars.githubusercontent.com/u/5311185?v=4)](https://github.com/akoepcke "akoepcke (2 commits)")[![ziming](https://avatars.githubusercontent.com/u/679513?v=4)](https://github.com/ziming "ziming (1 commits)")[![arthurkirkosa](https://avatars.githubusercontent.com/u/1099791?v=4)](https://github.com/arthurkirkosa "arthurkirkosa (1 commits)")[![drbyte](https://avatars.githubusercontent.com/u/404472?v=4)](https://github.com/drbyte "drbyte (1 commits)")[![fetzi](https://avatars.githubusercontent.com/u/3509426?v=4)](https://github.com/fetzi "fetzi (1 commits)")[![fridzema](https://avatars.githubusercontent.com/u/8180660?v=4)](https://github.com/fridzema "fridzema (1 commits)")[![introwit](https://avatars.githubusercontent.com/u/11228182?v=4)](https://github.com/introwit "introwit (1 commits)")[![krsriq](https://avatars.githubusercontent.com/u/2337648?v=4)](https://github.com/krsriq "krsriq (1 commits)")[![m1guelpf](https://avatars.githubusercontent.com/u/23558090?v=4)](https://github.com/m1guelpf "m1guelpf (1 commits)")[![Nielsvanpach](https://avatars.githubusercontent.com/u/10651054?v=4)](https://github.com/Nielsvanpach "Nielsvanpach (1 commits)")

---

Tags

artisandebugdevelopmentlaravelmailphptestspatielaravel-mailable-test

### Embed Badge

![Health badge](/badges/spatie-laravel-mailable-test/health.svg)

```
[![Health](https://phpackages.com/badges/spatie-laravel-mailable-test/health.svg)](https://phpackages.com/packages/spatie-laravel-mailable-test)
```

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

12.9k89.8M1.0k](/packages/spatie-laravel-permission)[spatie/laravel-health

Monitor the health of a Laravel application

85810.0M83](/packages/spatie-laravel-health)[spatie/laravel-ray

Easily debug Laravel apps

31738.4M2.8k](/packages/spatie-laravel-ray)[spatie/laravel-enum

Laravel Enum support

3655.4M31](/packages/spatie-laravel-enum)[spatie/laravel-failed-job-monitor

Get notified when a queued job fails

1.0k2.6M4](/packages/spatie-laravel-failed-job-monitor)[spatie/laravel-notification-log

Log notifications sent by your Laravel app

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

PHPackages © 2026

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