PHPackages                             alexandresalome/mailcatcher - 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. alexandresalome/mailcatcher

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

alexandresalome/mailcatcher
===========================

A library to access MailCatcher

v1.4.1(2y ago)1291.2M↓23.7%35[1 issues](https://github.com/alexandresalome/mailcatcher/issues)[2 PRs](https://github.com/alexandresalome/mailcatcher/pulls)2MITPHPPHP &gt;=5.3.3CI failing

Since Jul 9Pushed 2y ago2 watchersCompare

[ Source](https://github.com/alexandresalome/mailcatcher)[ Packagist](https://packagist.org/packages/alexandresalome/mailcatcher)[ RSS](/packages/alexandresalome-mailcatcher/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (9)Dependencies (4)Versions (16)Used By (2)

MailCatcher for PHP
===================

[](#mailcatcher-for-php)

[![Build status](https://camo.githubusercontent.com/8ab5d5e10a7d20121b2d55eadc93409c6ab8864735923e962264121ccd309bc7/68747470733a2f2f7472617669732d63692e6f72672f616c6578616e64726573616c6f6d652f6d61696c636174636865722e706e673f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/8ab5d5e10a7d20121b2d55eadc93409c6ab8864735923e962264121ccd309bc7/68747470733a2f2f7472617669732d63692e6f72672f616c6578616e64726573616c6f6d652f6d61696c636174636865722e706e673f6272616e63683d6d6173746572) [![Latest Stable Version](https://camo.githubusercontent.com/f33605b6315d010d206f53240c481fca15329c611f037c692ce87c91cd298255/68747470733a2f2f706f7365722e707567782e6f72672f616c6578616e64726573616c6f6d652f6d61696c636174636865722f762f737461626c65)](https://packagist.org/packages/alexandresalome/mailcatcher) [![Total Downloads](https://camo.githubusercontent.com/48c26045322157ec956be529372003ba5077012c6a3dace52ab86a79eaf39ff4/68747470733a2f2f706f7365722e707567782e6f72672f616c6578616e64726573616c6f6d652f6d61696c636174636865722f646f776e6c6f616473)](https://packagist.org/packages/alexandresalome/mailcatcher) [![License](https://camo.githubusercontent.com/ab0f99db0db3f514e85f95dd7a53d05be07b55fdacd616226526b83134ff87ce/68747470733a2f2f706f7365722e707567782e6f72672f616c6578616e64726573616c6f6d652f6d61696c636174636865722f6c6963656e7365)](https://packagist.org/packages/alexandresalome/mailcatcher) [![Monthly Downloads](https://camo.githubusercontent.com/c3faed14a6c0b553e64795add55ce53aded34304b75984d2dd5a7b9e4c890389/68747470733a2f2f706f7365722e707567782e6f72672f616c6578616e64726573616c6f6d652f6d61696c636174636865722f642f6d6f6e74686c79)](https://packagist.org/packages/alexandresalome/mailcatcher) [![Daily Downloads](https://camo.githubusercontent.com/7523c3282d8450b83ed7f2c0f38b3c054ee7288537aa507073ff4103346aded2/68747470733a2f2f706f7365722e707567782e6f72672f616c6578616e64726573616c6f6d652f6d61696c636174636865722f642f6461696c79)](https://packagist.org/packages/alexandresalome/mailcatcher)

Integrates [MailCatcher](http://mailcatcher.me) in your PHP application.

- [View CHANGELOG](CHANGELOG.md)
- [View CONTRIBUTORS](CONTRIBUTORS.md)

MailCatcher is a simple SMTP server with an HTTP API, and this library aims to integrate it to make it easy to use it with PHP.

Behat extension
---------------

[](#behat-extension)

This library provides a Behat extension to help you test mails in your application.

To use it, you first need to be sure [MailCatcher](http://mailcatcher.me) is properly installed and running. You can use docker to execute it:

```
docker run -d -p 1080:1080 -p 1025:1025 --name mailcatcher schickling/mailcatcher
```

First, configure in your `behat.yml`:

```
default:
    extensions:
        Alex\MailCatcher\Behat\MailCatcherExtension\Extension:
            url: http://localhost:1080
            purge_before_scenario: true
```

Then, add the **MailCatcherContext** context in your **FeatureContext** file:

```
use Alex\MailCatcher\Behat\MailCatcherContext;
use Behat\Behat\Context\BehatContext;

class FeatureContext extends BehatContext
{
   public function __construct(array $parameters)
   {
      $this->useContext('mailcatcher', new MailCatcherContext());
   }
}
```

### Available steps

[](#available-steps)

This extension provides you mail context in your tests. To use assertions, you must first **open a mail** using criterias.

Once it's opened, you can make **assertions** on it and **click** in it.

**Server manipulation**

Deletes all messages on the server

- When I purge mails

**Mail opening**

- When I open mail from "****"
- When I open mail containing "**a message**"
- When I open mail to "****"
- When I open mail with subject "**Welcome, mister Bond!**"

**Assertion**

Verify number of messages sent to the server:

- Then **1** mail should be sent
- Then **13** mails should be sent

Verify text presence in message:

- Then I should see "**something**" in mail
- Then I should see "**something else**" in mail

Verify text presence in mail without opening:

- Then I should see mail from "****"
- Then I should see mail containing "**a message**"
- Then I should see mail to "****"
- Then I should see mail with subject "**Welcome, mister Bond!**"

### Custom mailcatcher context

[](#custom-mailcatcher-context)

**Only available from PHP 5.4**

If you want to create a context class that relates to MailCatcher, you can use the **MailCatcherTrait** to get the mailcatcher client injected inside your class:

```
use Alex\MailCatcher\Behat\MailCatcherAwareInterface;
use Alex\MailCatcher\Behat\MailCatcherTrait;
use Alex\MailCatcher\Message;
use Behat\Behat\Context\Context;

class WelcomeContext implements Context, MailCatcherAwareInterface
{
    use MailCatcherTrait;

    /**
     * @Then /^a welcome mail should be sent$/
     */
    public function testTrait()
    {
        $this->findMail(Message::SUBJECT_CRITERIA, 'Welcome!');
    }
}
```

This trait offers the following methods:

- **getMailCatcherClient()**: returns the mailcatcher **Client** instance.
- **findMail($criteria, $value)**: facility to search for a given message, or throws an exception if not found

**Don't forget** to implement the **MailCatcherAwareInterface** to get the mailcatcher client injected inside your context class.

Client API
----------

[](#client-api)

Browse easily your API with the integrated SDK:

```
$client = new Alex\MailCatcher\Client('http://localhost:1080');

// Returns all messages
$messages = $client->search();

// Count messages
$client->getMessageCount();

// Filter messages
$messages = $client->search(array(
    'from'        => 'bob@example.org',
    'to'          => 'alice@example.org',
    'subject'     => 'Bla',
    'contains'    => 'Hello',
    'attachments' => true,
    'format'      => 'html',
), $limit = 3);

// Search one message
$message = $client->searchOne(array('subject' => 'Welcome'));
```

**Message API**

```
// Message API, get the content of a message
$subject = $message->getSubject();
$plainTextBody = $message->getPart('text/plain')->getContent();
$htmlBody = $message->getPart('text/html')->getContent();

// Message API, return a Person object or an array of Person object
$person  = $message->getFrom();
$persons = $message->getRecipients();

// Person API
$person = $message->getFrom();

$name = $person->getName(); // null means not provided
$mail = $person->getMail();

// Attachments
$message->hasAttachments();
$message->getAttachments();

// Delete
$message->delete();
```

**Attachment API**

```
// Attachment API
$attachment->getFilename();
$attachment->getSize();
$attachment->getType();
$attachment->getContent();
```

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity55

Moderate usage in the ecosystem

Community28

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor3

3 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

Every ~279 days

Recently: every ~333 days

Total

15

Last Release

780d ago

Major Versions

v0.3.0 → v1.0.02015-07-06

### Community

Maintainers

![](https://www.gravatar.com/avatar/2c6be58ec4620ddbcc6f95bf7353365dc7ff796c004c70369333aee6125eb309?d=identicon)[alexandresalome](/maintainers/alexandresalome)

---

Top Contributors

[![nucleartux](https://avatars.githubusercontent.com/u/199706?v=4)](https://github.com/nucleartux "nucleartux (12 commits)")[![alexandresalome](https://avatars.githubusercontent.com/u/134144?v=4)](https://github.com/alexandresalome "alexandresalome (10 commits)")[![mattparker](https://avatars.githubusercontent.com/u/112342?v=4)](https://github.com/mattparker "mattparker (9 commits)")[![akovalyov](https://avatars.githubusercontent.com/u/2339101?v=4)](https://github.com/akovalyov "akovalyov (2 commits)")[![diegohq](https://avatars.githubusercontent.com/u/1486939?v=4)](https://github.com/diegohq "diegohq (2 commits)")[![pfz](https://avatars.githubusercontent.com/u/1042926?v=4)](https://github.com/pfz "pfz (2 commits)")[![pierremarichez](https://avatars.githubusercontent.com/u/185425135?v=4)](https://github.com/pierremarichez "pierremarichez (2 commits)")[![pix-art](https://avatars.githubusercontent.com/u/1973973?v=4)](https://github.com/pix-art "pix-art (2 commits)")[![lyrixx](https://avatars.githubusercontent.com/u/408368?v=4)](https://github.com/lyrixx "lyrixx (1 commits)")[![blazarecki](https://avatars.githubusercontent.com/u/1443312?v=4)](https://github.com/blazarecki "blazarecki (1 commits)")[![alexislefebvre](https://avatars.githubusercontent.com/u/2071331?v=4)](https://github.com/alexislefebvre "alexislefebvre (1 commits)")[![OwlyCode](https://avatars.githubusercontent.com/u/1631270?v=4)](https://github.com/OwlyCode "OwlyCode (1 commits)")[![syl20b](https://avatars.githubusercontent.com/u/8626620?v=4)](https://github.com/syl20b "syl20b (1 commits)")[![troytft](https://avatars.githubusercontent.com/u/595612?v=4)](https://github.com/troytft "troytft (1 commits)")[![vincentmoulene](https://avatars.githubusercontent.com/u/7878654?v=4)](https://github.com/vincentmoulene "vincentmoulene (1 commits)")[![captbaritone](https://avatars.githubusercontent.com/u/162735?v=4)](https://github.com/captbaritone "captbaritone (1 commits)")[![damour](https://avatars.githubusercontent.com/u/881794?v=4)](https://github.com/damour "damour (1 commits)")[![sgomez](https://avatars.githubusercontent.com/u/580701?v=4)](https://github.com/sgomez "sgomez (1 commits)")[![gmorel](https://avatars.githubusercontent.com/u/2279794?v=4)](https://github.com/gmorel "gmorel (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/alexandresalome-mailcatcher/health.svg)

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

###  Alternatives

[minishlink/web-push

Web Push library for PHP

1.9k12.0M53](/packages/minishlink-web-push)[laravel-notification-channels/twilio

Provides Twilio notification channel for Laravel

2587.7M12](/packages/laravel-notification-channels-twilio)[spatie/url-signer

Generate a url with an expiration date and signature to prevent unauthorized access

4422.3M16](/packages/spatie-url-signer)[mattketmo/email-checker

Throwaway email detection library

2742.0M5](/packages/mattketmo-email-checker)[netflie/laravel-notification-whatsapp

Laravel notification driver for WhatsApp

176173.9k](/packages/netflie-laravel-notification-whatsapp)[opcodesio/mail-parser

Parse emails without the mailparse extension

226.8M8](/packages/opcodesio-mail-parser)

PHPackages © 2026

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