PHPackages                             chrisreedio/laravel-mailosaur - 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. chrisreedio/laravel-mailosaur

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

chrisreedio/laravel-mailosaur
=============================

Mailosaur SDK for Laravel

v1.0.0(9mo ago)021[5 PRs](https://github.com/chrisreedio/laravel-mailosaur/pulls)MITPHPPHP ^8.3CI passing

Since Aug 12Pushed 1mo agoCompare

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

READMEChangelog (1)Dependencies (14)Versions (8)Used By (0)

Mailosaur SDK for Laravel
=========================

[](#mailosaur-sdk-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/2d98a94f49c104289c3ea9de00356ace4c4b8f942f1162d8d3aa107b2355575c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636872697372656564696f2f6c61726176656c2d6d61696c6f736175722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/chrisreedio/laravel-mailosaur)[![GitHub Tests Action Status](https://camo.githubusercontent.com/26f395d6333b0d45c4742ed27a393576f571ccbe1753dea3eb3e784c121616e4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f636872697372656564696f2f6c61726176656c2d6d61696c6f736175722f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/chrisreedio/laravel-mailosaur/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/3f6fa4f912f4df2ad1fb47a85c483968fb0b8d6c5ea3fc736b3c8a2cb327871e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f636872697372656564696f2f6c61726176656c2d6d61696c6f736175722f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/chrisreedio/laravel-mailosaur/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/0da2e2bd57689d449e9c0f405fef0da08c407e9e0721e4f4e68417f94166533c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636872697372656564696f2f6c61726176656c2d6d61696c6f736175722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/chrisreedio/laravel-mailosaur)

Thin Laravel integration for the official Mailosaur PHP SDK. This package registers a singleton `MailosaurClient` configured from your app’s config/ENV, and exposes it via a simple wrapper class and a facade so you can call the Mailosaur API anywhere in your app.

> The PHP usage patterns below are based on the Mailosaur docs: [Mailosaur PHP – Find an email](https://mailosaur.com/docs/languages/php#4-find-an-email-for-automated-testing).

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

[](#requirements)

- PHP ^8.3
- Laravel ^10 || ^11 || ^12

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

[](#installation)

```
composer require chrisreedio/laravel-mailosaur
```

Publish the config file:

```
php artisan vendor:publish --tag="laravel-mailosaur-config"
```

Set your environment variables (recommended):

```
MAILOSAUR_API_KEY=your_api_key
MAILOSAUR_SERVER_ID=your_server_id
# Optional (defaults to "${MAILOSAUR_SERVER_ID}.mailosaur.net")
MAILOSAUR_EMAIL_DOMAIN=your-domain.mailosaur.net
```

The published config `config/mailosaur.php` reads from these ENV keys:

```
return [
    'api_key' => env('MAILOSAUR_API_KEY'),
    'server_id' => env('MAILOSAUR_SERVER_ID'),
    'domain' => env('MAILOSAUR_EMAIL_DOMAIN', env('MAILOSAUR_SERVER_ID').'.mailosaur.net'),
];
```

How it works
------------

[](#how-it-works)

- The service provider creates a singleton instance of `MailosaurClient` using `config('mailosaur.api_key')`.
- It wraps the client in `ChrisReedIO\Mailosaur\Mailosaur`, which also exposes your `serverId` and `domain` from config.
- A facade alias `Mailosaur` is registered for convenience.

Usage
-----

[](#usage)

You can access the same singleton three ways. Choose what fits your style:

1. Facade (convenient):

```
use ChrisReedIO\Mailosaur\Facades\Mailosaur; // or use the alias: use Mailosaur;

$client = Mailosaur::client();
$messages = Mailosaur::messages();
$serverId = Mailosaur::serverId();
$domain = Mailosaur::domain();
```

2. Dependency Injection:

```
use ChrisReedIO\Mailosaur\Mailosaur;

public function __construct(private Mailosaur $mailosaur) {}

public function __invoke()
{
    $client = $this->mailosaur->client();
}
```

3. Container helper:

```
$mailosaur = app(\ChrisReedIO\Mailosaur\Mailosaur::class);
```

Convenience methods (no server ID needed)
-----------------------------------------

[](#convenience-methods-no-server-id-needed)

These helpers use your configured `MAILOSAUR_SERVER_ID` automatically:

```
// Find a single message matching criteria
Mailosaur::getMessage(SearchCriteria $criteria, int $timeout = 10000, ?DateTime $receivedAfter = null, ?string $dir = null): \Mailosaur\Models\Message

// Search for messages
Mailosaur::searchMessages(SearchCriteria $criteria, int $page = 0, int $itemsPerPage = 50, ?int $timeout = null, ?DateTime $receivedAfter = null, bool $errorOnTimeout = true, ?string $dir = null): \Mailosaur\Models\MessageListResult

// List all messages
Mailosaur::allMessages(int $page = 0, int $itemsPerPage = 50, ?DateTime $receivedAfter = null, ?string $dir = null): \Mailosaur\Models\MessageListResult

// Delete all messages on the configured server
Mailosaur::deleteAllMessages(): void

// Create a message to a verified email address
Mailosaur::createMessage(\Mailosaur\Models\MessageCreateOptions $options): \Mailosaur\Models\Message

// Generate a random email address for the configured server
Mailosaur::generateEmailAddress(): string
```

### Examples using convenience methods

[](#examples-using-convenience-methods)

```
use ChrisReedIO\Mailosaur\Facades\Mailosaur;
use Mailosaur\Models\SearchCriteria;

// Get a single matching message
$criteria = new SearchCriteria();
$criteria->sentTo = 'anything@' . Mailosaur::domain();
$message = Mailosaur::getMessage($criteria);

// Search with timeout and receivedAfter
$testStart = new \DateTime();
$result = Mailosaur::searchMessages($criteria, itemsPerPage: 10, timeout: 10_000, receivedAfter: $testStart);

// List and delete all
$list = Mailosaur::allMessages(itemsPerPage: 10);
Mailosaur::deleteAllMessages();

// Generate a random address on the configured server
$address = Mailosaur::generateEmailAddress();
```

Common examples
---------------

[](#common-examples)

### Find an email (wait for the next matching message)

[](#find-an-email-wait-for-the-next-matching-message)

```
use ChrisReedIO\Mailosaur\Facades\Mailosaur;
use Mailosaur\Models\SearchCriteria;

$criteria = new SearchCriteria();
$criteria->sentTo = 'anything@' . Mailosaur::domain();

// Using raw SDK (requires serverId)
$message = Mailosaur::messages()->get(Mailosaur::serverId(), $criteria);
// Or with convenience method (no serverId needed)
// $message = Mailosaur::getMessage($criteria);

// e.g. assert subject
// expect($message->subject)->toBe('My example email');
```

### Wait with custom timeout and only include messages received after test start

[](#wait-with-custom-timeout-and-only-include-messages-received-after-test-start)

```
use ChrisReedIO\Mailosaur\Facades\Mailosaur;
use Mailosaur\Models\SearchCriteria;

$testStart = new \DateTime();

$criteria = new SearchCriteria();
$criteria->sentTo = 'anything@' . Mailosaur::domain();

// timeout in ms, receivedAfter as DateTime
$message = Mailosaur::getMessage(
    criteria: $criteria,
    timeout: 10_000,
    receivedAfter: $testStart
);
```

### Generate a random email address for the server

[](#generate-a-random-email-address-for-the-server)

```
use ChrisReedIO\Mailosaur\Facades\Mailosaur;

$emailAddress = Mailosaur::generateEmailAddress();
// e.g. "bgwqj@SERVER_ID.mailosaur.net"
```

### Delete all messages on the server

[](#delete-all-messages-on-the-server)

```
use ChrisReedIO\Mailosaur\Facades\Mailosaur;

Mailosaur::deleteAllMessages();
```

For many more operations (attachments, forwarding, replying, etc.), see the official Mailosaur PHP docs: [Mailosaur PHP – Find an email](https://mailosaur.com/docs/languages/php#4-find-an-email-for-automated-testing).

Testing
-------

[](#testing)

```
composer test
```

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 Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Chris Reed](https://github.com/chrisreedio)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance77

Regular maintenance activity

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

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

274d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/edf125933a93f1f09822d1679b36b2d6deed75b2380f6e1c57d54cd52a8db29d?d=identicon)[chrisreedio](/maintainers/chrisreedio)

---

Top Contributors

[![chrisreedio](https://avatars.githubusercontent.com/u/77644584?v=4)](https://github.com/chrisreedio "chrisreedio (9 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

laravelChris Reedlaravel-mailosaur

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/chrisreedio-laravel-mailosaur/health.svg)

```
[![Health](https://phpackages.com/badges/chrisreedio-laravel-mailosaur/health.svg)](https://phpackages.com/packages/chrisreedio-laravel-mailosaur)
```

###  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)[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)[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)

PHPackages © 2026

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