PHPackages                             kirschbaum-development/mail-intercept - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. kirschbaum-development/mail-intercept

ActiveLibrary[Testing &amp; Quality](/categories/testing)

kirschbaum-development/mail-intercept
=====================================

A test package for intercepting email sent from Laravel

v1.0.1(1y ago)112407.9k↓12.3%8[1 PRs](https://github.com/kirschbaum-development/mail-intercept/pulls)1MITPHPPHP ^8.1|^8.2CI passing

Since Dec 12Pushed 1y ago13 watchersCompare

[ Source](https://github.com/kirschbaum-development/mail-intercept)[ Packagist](https://packagist.org/packages/kirschbaum-development/mail-intercept)[ Docs](https://github.com/kirschbaum-development/mail-intercept)[ RSS](/packages/kirschbaum-development-mail-intercept/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (17)Used By (1)

[![Mail Intercept banner](screenshots/banner.jpg)](screenshots/banner.jpg)

Laravel Mail Intercept
======================

[](#laravel-mail-intercept)

### A testing package for intercepting mail sent from Laravel

[](#a-testing-package-for-intercepting-mail-sent-from-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/be5c159db61be924f495a67d973b593278d4e06a009814627ade80881dbfe8a9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b69727363686261756d2d646576656c6f706d656e742f6d61696c2d696e746572636570742e737667)](https://packagist.org/packages/kirschbaum-development/mail-intercept)[![Total Downloads](https://camo.githubusercontent.com/d3f86b3d884331d60541505101764c55b68ed8fce694938b1810c0e167caa43b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b69727363686261756d2d646576656c6f706d656e742f6d61696c2d696e746572636570742e737667)](https://packagist.org/packages/kirschbaum-development/mail-intercept)[![Codacy Badge](https://camo.githubusercontent.com/b76bd577ff142e306e65c6fd7da603deaea1d819a0df6d83b9d203bfa263e9cb/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f6363303734393938376333383432366562633862303035396331313731653237)](https://www.codacy.com/manual/Kirschbaum/mail-intercept?utm_source=github.com&utm_medium=referral&utm_content=kirschbaum-development/mail-intercept&utm_campaign=Badge_Grade)[![Actions Status](https://github.com/kirschbaum-development/mail-intercept/workflows/CI/badge.svg)](https://github.com/kirschbaum-development/mail-intercept/actions)

This testing suite intercepts Laravel Mail just before they are sent out, allowing all kinds of assertions to be made on the actual emails themselves.

Mail isn't faked here. You get to inspect the actual mail ensuring you are sending exactly what you want!

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

[](#requirements)

Laravel VersionMail Intercept Version10.x &amp; 11.01.0.x9.x0.3.x8.x and lower0.2.xPlease note: If you are using `v0.2.x`, please refer to that version's [documentation](https://github.com/kirschbaum-development/mail-intercept/tree/v0.2.x).

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

[](#installation)

```
composer require kirschbaum-development/mail-intercept --dev
```

Usage
-----

[](#usage)

Next you can use the `KirschbaumDevelopment\MailIntercept\WithMailInterceptor` trait in your test class:

```
namespace Tests;

use App\Mail\TestMail;
use Illuminate\Support\Facades\Mail;
use Illuminate\Foundation\Testing\WithFaker;
use KirschbaumDevelopment\MailIntercept\WithMailInterceptor;

class MailTest extends TestCase
{
    use WithFaker;
    use WithMailInterceptor;

    public function testMail()
    {
        $this->interceptMail();

        $email = $this->faker->email;

        Mail::to($email)->send(new TestMail());

        $interceptedMail = $this->interceptedMail()->first();

        $interceptedMail->assertSentTo($email);
    }
}
```

That's it! Pretty simple, right?!

There are two ways of accessing the assertions. First is the fluent syntax directly on each intercepted email.

```
$interceptedMail->assertSentTo($email);
```

The other way (the older way) is to use the assertions methods made available from the `WithMailInterceptor` trait. Using these methods are fine, but aren't as clean to write.

```
$this->assertMailSentTo($email, $interceptedEmail);
```

Both of these assertions do the exact same thing, the fluent one is just much cleaner. See all the available assertion methods below!

### Testing API

[](#testing-api)

```
$this->interceptMail()
```

This method MUST be called first, similar to how `Mail::fake()` works. But unlike the mail fake, mail is not faked, it is intercepted.

```
$this->interceptedMail()
```

This should be called after `Mail` has been sent, but before your assertions, otherwise you won't have any emails to work with. It returns a `Collection` of emails so you are free to use any of the methods available to a collection.

#### Fluent Assertion Methods

[](#fluent-assertion-methods)

AssertionsParameters`$intercepted->assertSentTo($to);``$to` array, string`$intercepted->assertNotSentTo($to);``$to` array, string`$intercepted->assertSentFrom($from);``$from` array, string`$intercepted->assertNotSentFrom($from);``$from` array, string`$intercepted->assertSubject($subject);``$subject` string`$intercepted->assertNotSubject($subject);``$subject` string`$intercepted->assertBodyContainsString($content);``$content` string`$intercepted->assertBodyNotContainsString($content);``$content` string`$intercepted->assertRepliesTo($reply);``$reply` array, string`$intercepted->assertNotRepliesTo($reply);``$reply` array, string`$intercepted->assertCc($cc);``$cc` array, string`$intercepted->assertNotCc($cc);``$cc` array, string`$intercepted->assertBcc($cc);``$bcc` array, string`$intercepted->assertNotBcc($cc);``$bcc` array, string`$intercepted->assertSender($sender);``$sender` array, string`$intercepted->assertNotSender($sender);``$sender` array, string`$intercepted->assertReturnPath($returnPath);``$returnPath` string`$intercepted->assertNotReturnPath($returnPath);``$returnPath` stringContent Type Assertions`$intercepted->assertIsPlain();``$intercepted->assertIsNotPlain();``$intercepted->assertHasPlainContent();``$intercepted->assertDoesNotHavePlainContent();``$intercepted->assertIsHtml();``$intercepted->assertIsNotHtml();``$intercepted->assertHasHtmlContent();``$intercepted->assertDoesNotHaveHtmlContent();``$intercepted->assertIsAlternative();``$intercepted->assertIsNotAlternative();``$intercepted->assertIsMixed();``$intercepted->assertIsNotMixed();`Header AssertionsParameters`$intercepted->assertHasHeader($header);``$header` string`$intercepted->assertMissingHeader($header);``$header` string`$intercepted->assertHeaderIs($header, $value);``$header` string
`$value` string`$intercepted->assertHeaderIsNot($header, $value);``$header` string
`$value` stringPriority AssertionsParameters`$intercepted->assertPriority($priority);``$priority` int`$intercepted->assertNotPriority($priority);``$priority` int`$intercepted->assertPriorityIsHighest();``$intercepted->assertPriorityNotHighest();``$intercepted->assertPriorityIsHigh();``$intercepted->assertPriorityNotHigh();``$intercepted->assertPriorityIsNormal();``$intercepted->assertPriorityNotNormal();``$intercepted->assertPriorityIsLow();``$intercepted->assertPriorityNotLow();``$intercepted->assertPriorityIsLowest();``$intercepted->assertPriorityIsLowest();`Attachment AssertionsParameters`$intercepted->assertHasAttachment($filename);``$filename` string`$intercepted->assertHasAttachments();``$intercepted->assertMissingAttachment($filename);``$filename` string`$intercepted->assertMissingAttachments();``$intercepted->assertHasEmbeddedImage($filename);``$filename` string`$intercepted->assertHasEmbeddedImages();``$intercepted->assertMissingEmbeddedImage($filename);``$filename` string`$intercepted->assertMissingEmbeddedImages();`#### Assertion Methods

[](#assertion-methods)

AssertionsParameters`$this->assertMailSentTo($to, $mail);``$to` array, string
`$mail` AssertableMessage, Email`$this->assertMailNotSentTo($to, $mail);``$to` array, string
`$mail` AssertableMessage, Email`$this->assertMailSentFrom($from, $mail);``$from` array, string
`$mail` AssertableMessage, Email`$this->assertMailNotSentFrom($from, $mail);``$from` array, string
`$mail` AssertableMessage, Email`$this->assertMailSubject($subject, $mail);``$subject` string
`$mail` AssertableMessage, Email`$this->assertMailNotSubject($subject, $mail);``$subject` string
`$mail` AssertableMessage, Email`$this->assertMailBodyContainsString($content, $mail);``$content` string
`$mail` AssertableMessage, Email`$this->assertMailBodyNotContainsString($content, $mail);``$content` string
`$mail` AssertableMessage, Email`$this->assertMailRepliesTo($reply, $mail);``$reply` array, string
`$mail` AssertableMessage, Email`$this->assertMailNotRepliesTo($reply, $mail);``$reply` array, string
`$mail` AssertableMessage, Email`$this->assertMailCc($cc, $mail);``$cc` array, string
`$mail` AssertableMessage, Email`$this->assertMailNotCc($cc, $mail);``$cc` array, string
`$mail` AssertableMessage, Email`$this->assertMailBcc($cc, $mail);``$bcc` array, string
`$mail` AssertableMessage, Email`$this->assertMailNotBcc($cc, $mail);``$bcc` array, string
`$mail` AssertableMessage, Email`$this->assertMailSender($sender, $mail);``$sender` array, string
`$mail` AssertableMessage, Email`$this->assertMailNotSender($sender, $mail);``$sender` array, string
`$mail` AssertableMessage, Email`$this->assertMailReturnPath($returnPath, $mail);``$returnPath` string
`$mail` AssertableMessage, Email`$this->assertMailNotReturnPath($returnPath, $mail);``$returnPath` string
`$mail` AssertableMessage, EmailContent Type AssertionsParameters`$this->assertMailIsPlain($mail);``$mail` AssertableMessage, Email`$this->assertMailIsNotPlain($mail);``$mail` AssertableMessage, Email`$this->assertMailHasPlainContent($mail);``$mail` AssertableMessage, Email`$this->assertMailDoesNotHavePlainContent($mail);``$mail` AssertableMessage, Email`$this->assertMailIsHtml($mail);``$mail` AssertableMessage, Email`$this->assertMailIsNotHtml($mail);``$mail` AssertableMessage, Email`$this->assertMailHasHtmlContent($mail);``$mail` AssertableMessage, Email`$this->assertMailDoesNotHaveHtmlContent($mail);``$mail` AssertableMessage, Email`$this->assertMailIsAlternative($mail);``$mail` AssertableMessage, Email`$this->assertMailIsNotAlternative($mail);``$mail` AssertableMessage, Email`$this->assertMailIsMixed($mail);``$mail` AssertableMessage, Email`$this->assertMailIsNotMixed($mail);``$mail` AssertableMessage, EmailHeader AssertionsParameters`$this->assertMailHasHeader($header, $mail);``$header` string
`$mail` AssertableMessage, Email`$this->assertMailMissingHeader($header, $mail);``$header` string
`$mail` AssertableMessage, Email`$this->assertMailHeaderIs($header, $value, $mail);``$header` string
`$value` string
`$mail` AssertableMessage, Email`$this->assertMailHeaderIsNot($header, $value, $mail);``$header` string
`$value` string
`$mail` AssertableMessage, EmailPriority AssertionsParameters`$this->assertMailPriority($priority, $mail);``$priority` int
`$mail` AssertableMessage, Email`$this->assertMailNotPriority($priority, $mail);``$priority` int
`$mail` AssertableMessage, Email`$this->assertMailPriorityIsHighest($mail);``$mail` AssertableMessage, Email`$this->assertMailPriorityNotHighest($mail);``$mail` AssertableMessage, Email`$this->assertMailPriorityIsHigh($mail);``$mail` AssertableMessage, Email`$this->assertMailPriorityNotHigh($mail);``$mail` AssertableMessage, Email`$this->assertMailPriorityIsNormal($mail);``$mail` AssertableMessage, Email`$this->assertMailPriorityNotNormal($mail);``$mail` AssertableMessage, Email`$this->assertMailPriorityIsLow($mail);``$mail` AssertableMessage, Email`$this->assertMailPriorityNotLow($mail);``$mail` AssertableMessage, Email`$this->assertMailPriorityIsLowest($mail);``$mail` AssertableMessage, Email`$this->assertMailPriorityIsLowest($mail);``$mail` AssertableMessage, EmailAttachment AssertionsParameters`this->assertMailHasAttachment($filename);``$filename` string
`$mail` AssertableMessage, Email`this->assertMailHasAttachments();``$mail` AssertableMessage, Email`this->assertMailMissingAttachment($filename);``$filename` string
`$mail` AssertableMessage, Email`this->assertMailMissingAttachments();``$mail` AssertableMessage, Email`this->assertMailHasEmbeddedImage($filename);``$filename` string
`$mail` AssertableMessage, Email`this->assertMailHasEmbeddedImages();``$mail` AssertableMessage, Email`this->assertMailMissingEmbeddedImage($filename);``$filename` string
`$mail` AssertableMessage, Email`this->assertMailMissingEmbeddedImages();``$mail` AssertableMessage, EmailYou should use each item of the `interceptedMail()` collection as the mail object for all assertions.

If you are injecting your own headers or need access to other headers in the email, use this assertion to verify they exist and are set properly. These assertions require the header name and the compiled email.

### Other assertions

[](#other-assertions)

Since `$this->interceptedMail()` returns a collection of `AssertableMessage` objects. You are free to dissect and look into those objects using any methods available to Symfony's Email API. Head over to the [Symfony Email Docs](https://symfony.com/doc/current/mailer.html) for more detailed info.

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

[](#security)

If you discover any security related issues, please email  or  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Brandon Ferens](https://github.com/brandonferens)
- [Michael Fox](https://github.com/michaelfox)

Sponsorship
-----------

[](#sponsorship)

Development of this package is sponsored by Kirschbaum Development Group, a developer driven company focused on problem solving, team building, and community. Learn more [about us](https://kirschbaumdevelopment.com) or [join us](https://careers.kirschbaumdevelopment.com)!

License
-------

[](#license)

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

###  Health Score

53

—

FairBetter than 97% of packages

Maintenance45

Moderate activity, may be stable

Popularity50

Moderate usage in the ecosystem

Community25

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 83.1% 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 ~136 days

Recently: every ~250 days

Total

15

Last Release

432d ago

Major Versions

v0.5.0 → v1.0.02024-10-21

PHP version history (5 changes)v0.1.0PHP &gt;=7.0

v0.3.0PHP ^8.0.2

v0.4.0PHP ^8.0.2|^8.1

v0.5.0PHP ^8.0.2|^8.1|^8.2

v1.0.0PHP ^8.1|^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/5f56743d64d77958321d43b2df49e9696d19c9dd99995730c5c38ccae50408fa?d=identicon)[Kirschbaum](/maintainers/Kirschbaum)

![](https://www.gravatar.com/avatar/66b8ba124c4a8a7b5a6544665d0f7b48f78a3608e92b70ab03a7562a0a8dde07?d=identicon)[brandonferens](/maintainers/brandonferens)

---

Top Contributors

[![brandonferens](https://avatars.githubusercontent.com/u/1819546?v=4)](https://github.com/brandonferens "brandonferens (74 commits)")[![dvanscott](https://avatars.githubusercontent.com/u/38760117?v=4)](https://github.com/dvanscott "dvanscott (5 commits)")[![michaelfox](https://avatars.githubusercontent.com/u/37444?v=4)](https://github.com/michaelfox "michaelfox (3 commits)")[![cstriuli](https://avatars.githubusercontent.com/u/3141550?v=4)](https://github.com/cstriuli "cstriuli (2 commits)")[![therobfonz](https://avatars.githubusercontent.com/u/35386780?v=4)](https://github.com/therobfonz "therobfonz (1 commits)")[![wilkerwma](https://avatars.githubusercontent.com/u/4114438?v=4)](https://github.com/wilkerwma "wilkerwma (1 commits)")[![crynobone](https://avatars.githubusercontent.com/u/172966?v=4)](https://github.com/crynobone "crynobone (1 commits)")[![ejunker](https://avatars.githubusercontent.com/u/4758?v=4)](https://github.com/ejunker "ejunker (1 commits)")[![patricksamson](https://avatars.githubusercontent.com/u/1416027?v=4)](https://github.com/patricksamson "patricksamson (1 commits)")

---

Tags

testlaravelemailsymfony mailer

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/kirschbaum-development-mail-intercept/health.svg)

```
[![Health](https://phpackages.com/badges/kirschbaum-development-mail-intercept/health.svg)](https://phpackages.com/packages/kirschbaum-development-mail-intercept)
```

###  Alternatives

[sofa/eloquent-testsuite

Helpers for fast and reliable UNIT tests for your Eloquent Models with PHPUnit

10104.7k](/packages/sofa-eloquent-testsuite)

PHPackages © 2026

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