PHPackages                             darvis/mailtrap - 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. darvis/mailtrap

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

darvis/mailtrap
===============

A Laravel package for Mailtrap integration

v1.0.14(1w ago)0135↓25%MITPHPPHP ^8.1

Since Sep 25Pushed 1w agoCompare

[ Source](https://github.com/ArvidDeJong/mailtrap)[ Packagist](https://packagist.org/packages/darvis/mailtrap)[ RSS](/packages/darvis-mailtrap/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (20)Versions (14)Used By (0)

Darvis Mailtrap Package
=======================

[](#darvis-mailtrap-package)

A powerful Laravel package for Mailtrap integration: email validation, automatic logging of outgoing mail, a Mailtrap-style inbox UI and a CLI health-check command.

[![Laravel](https://camo.githubusercontent.com/49180e08c9d2bf7321e8c7b5e2e6d04688dfe7dc215442c6e87bb62a1943800c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31322d7265642e737667)](https://laravel.com)[![PHP](https://camo.githubusercontent.com/45d36955804bf3f4f17097b05a7f41a28e578dc24e0d3ad0d21ae9d9762f44c6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e312b2d626c75652e737667)](https://php.net)

🚀 Quick Start
-------------

[](#-quick-start)

```
use Darvis\Mailtrap\Models\EmailValidation;

// Validate a single email address (returns null if valid, error message if invalid)
$errorMessage = EmailValidation::validateEmail('user@example.com');
$isValid = $errorMessage === null;

// Bulk validation of multiple email addresses
$emails = ['user1@test.com', 'user2@example.com', 'user3@invalid.domain'];
$result = EmailValidation::bulkValidationStatus($emails);

echo "Valid emails: " . $result['valid'];
echo "Invalid emails: " . $result['invalid'];
```

📚 Documentation
---------------

[](#-documentation)

For complete documentation and extensive examples:

### 📖 **[Go to Documentation →](./docs/)**

[](#-go-to-documentation-)

**Specific topics:**

- **[EmailValidation Model](./docs/email-validation.md)** - Complete guide for email validation
- **[Laravel Collections](./docs/email-validation/laravel-collections.md)** - Advanced filtering and data manipulation
- **[API Reference](./docs/email-validation/api-reference.md)** - All available methods
- **[Practical Examples](./docs/email-validation/examples.md)** - Real-world use cases
- **[Best Practices](./docs/email-validation/best-practices.md)** - Performance and error handling

✨ Features
----------

[](#-features)

### 🎯 **Email Validation**

[](#-email-validation)

- ✅ **Format Validation** - Checks basic email format
- ✅ **MX Record Verification** - Verifies domain mail servers
- ✅ **IP Validation** - Checks if MX records point to valid IPs
- ✅ **Bulk Validation** - Efficient validation of multiple email addresses
- ✅ **Laravel Collections** - Powerful filtering and data manipulation
- ✅ **Status Tracking** - Maintains validation history

### 🔧 **Integration &amp; Performance**

[](#-integration--performance)

- ✅ **Database Caching** - Fast lookups of previously validated emails
- ✅ **Automatic Registration** - Laravel package discovery
- ✅ **Event Listeners** - Automatic validation via Laravel mail events
- ✅ **Mailer-independent** - Logging &amp; validation work with any transport (Mailtrap, Microsoft Graph, SES, …)
- ✅ **Rate Limiting** - Built-in API rate limiting
- ✅ **Webhook Support** - Mailtrap callback support

### 📊 **Monitoring &amp; Logging**

[](#-monitoring--logging)

- ✅ **Mail Logging** - Automatic logging of outgoing emails
- ✅ **Detailed Tracking** - Comprehensive validation reporting
- ✅ **Status Codes** - HTTP-like status codes for categorization
- ✅ **Configurable** - Extensive configuration options

### 📬 **Inbox UI &amp; Tooling**

[](#-inbox-ui--tooling)

- ✅ **Mailtrap-style Inbox** - Livewire/Flux page to inspect every outgoing email
- ✅ **Search &amp; Filters** - Filter by status (sent, pending, failed, blocked) and search recipient/sender/subject
- ✅ **Send Test Mail** - Trigger a test email straight from the inbox
- ✅ **Delete &amp; Cleanup** - Remove a single log or purge logs older than the retention period
- ✅ **`mailtrap:test` Command** - CLI health-check with CI-friendly exit codes

Author
------

[](#author)

**Arvid de Jong**
Email:

📦 Installation
--------------

[](#-installation)

Install the package via Composer:

```
composer require darvis/mailtrap
```

⚙️ Configuration
----------------

[](#️-configuration)

The package is automatically registered via Laravel's package discovery.

### Database Setup

[](#database-setup)

Migrations are automatically loaded. To publish migrations to your application:

```
php artisan vendor:publish --tag=mailtrap-migrations
php artisan migrate
```

Or simply run `php artisan migrate` - migrations are loaded automatically.

### Configuration

[](#configuration)

Publish the config file for custom settings:

```
php artisan vendor:publish --tag=mailtrap-config
```

This creates a `config/manta_mailtrap.php` file with configuration for:

- **API Settings** - Mailtrap API token and base URL
- **Email Validation** - Validation settings and caching
- **Mail Logging** - Log settings for outgoing emails (incl. `cleanup_after_days` retention)
- **Webhook** - Webhook configuration and signature verification
- **Rate Limiting** - API rate limiting settings
- **Inbox UI** - Route, middleware, layout and page size for the inbox

**Environment Variables:**

```
MAILTRAP_API_TOKEN=your_api_token_here
MAILTRAP_VALIDATION_ENABLED=true
MAILTRAP_LOGGING_ENABLED=true
MAILTRAP_CLEANUP_AFTER_DAYS=30
MAILTRAP_WEBHOOK_ENABLED=true
MAILTRAP_WEBHOOK_SECRET=your_webhook_secret

# Inbox UI
MAILTRAP_UI_ENABLED=true
MAILTRAP_UI_ROUTE=mailtrap
MAILTRAP_UI_MIDDLEWARE=web,auth
MAILTRAP_UI_LAYOUT=components.layouts.app
MAILTRAP_UI_PER_PAGE=25
```

💡 Usage Examples
----------------

[](#-usage-examples)

### Basic Usage

[](#basic-usage)

```
// Via the Mailtrap service
$mailtrap = app(Darvis\Mailtrap\Services\MailtrapService::class);

// Or via the alias
$mailtrap = app('mailtrap');

// Email validation
$isValid = $mailtrap->validateEmail('test@example.com');
```

### Laravel Collections Filtering

[](#laravel-collections-filtering)

```
use Darvis\Mailtrap\Models\EmailValidation;

$emails = ['valid@test.com', 'invalid@spam.com', 'unknown@new.com'];
$result = EmailValidation::bulkValidationStatus($emails);

// Filter invalid emails with Laravel Collections
$invalidEmails = collect($result['details'])
    ->filter(fn($details) => $details['status'] !== 'valid')
    ->keys()
    ->toArray();

// Group by status
$grouped = collect($result['details'])
    ->groupBy('status')
    ->map(fn($group) => $group->keys()->toArray());
```

**📖 [More examples in the documentation →](./docs/email-validation/examples.md)**

📬 Inbox UI
----------

[](#-inbox-ui)

A Mailtrap-style inbox to inspect outgoing mail, built with Livewire and Flux UI.

> **Requirements:** the host application must have `livewire/livewire` and `livewire/flux` installed. When Livewire is absent (or `MAILTRAP_UI_ENABLED=false`) the UI registration is skipped automatically — the rest of the package keeps working.

Once enabled, the inbox lives at the configured route (default `/mailtrap`) and offers:

- A paginated list of all logged mail with status badges (sent, pending, failed, blocked)
- Search by recipient, sender or subject, and filter by status
- A detail view per message (message id, status, error, source file/line, linked model)
- A **Send test mail** action straight from the inbox
- **Delete** a single log, or **Cleanup** logs older than `logging.cleanup_after_days`

### Configuration

[](#configuration-1)

All UI settings are driven by environment variables (see the `ui` section in `config/manta_mailtrap.php`):

```
MAILTRAP_UI_ENABLED=true
MAILTRAP_UI_ROUTE=mailtrap
MAILTRAP_UI_MIDDLEWARE=web,auth        # comma-separated middleware stack
MAILTRAP_UI_LAYOUT=components.layouts.app
MAILTRAP_UI_PER_PAGE=25
```

> Protect the route with appropriate middleware — the inbox exposes recipients, subjects and error details. For example `MAILTRAP_UI_MIDDLEWARE=web,auth` (or a custom staff/admin middleware).

### Tailwind / Flux

[](#tailwind--flux)

Add the package views to your Tailwind sources so its utility classes are compiled (Tailwind v4 example in `resources/css/app.css`):

```
@source '../../vendor/darvis/mailtrap/resources/views/**/*.blade.php';
```

Optionally publish the views to override them in your application:

```
php artisan vendor:publish --tag=mailtrap-views
```

📮 Mail Transport vs. Mailtrap
-----------------------------

[](#-mail-transport-vs-mailtrap)

This package hooks into Laravel's `MessageSending` / `MessageSent` events, so it works **independently of the mailer (transport) you send through**. Sending via Mailtrap's SMTP, Microsoft Graph, Amazon SES or any other Laravel mailer all flow through the same pipeline — pre-send validation and `MailLog` logging happen for every transport.

The webhook flow is the one exception: delivery, open, click, bounce, spam and reject events are reported **only by Mailtrap**. If you send through another transport (e.g. `microsoft-graph`), local logging and validation still work, but there is no post-delivery feedback to confirm or invalidate addresses.

CapabilityAny mailerMailtrap onlyPre-send validation (format / MX / blocklist)✅Outgoing mail logging (`MessageSending` / `MessageSent`)✅Inbox UI &amp; `mailtrap:test` health check✅Delivery / open / click confirmation → `markAsValid`✅ (webhook)Bounce / spam / reject → `markAsInvalid`✅ (webhook)> **In practice:** you can route production mail through Microsoft Graph and still get full logging and the inbox UI. To also keep the validation feedback loop — auto-confirming good addresses and flagging bounces — the delivery events must come from Mailtrap.

🩺 Health Check Command
----------------------

[](#-health-check-command)

Send a test email and report the result. The command returns exit code `0` on success and `1` on failure, which makes it suitable for CI pipelines and uptime monitoring.

```
php artisan mailtrap:test you@example.com

# Use a specific mailer instead of the default
php artisan mailtrap:test you@example.com --mailer=microsoft-graph
```

It sends the mail, reads back the corresponding mail log and prints a summary table (message id, sender, recipient, subject, status, error message). A recorded non-success status (e.g. a blocked recipient) is also treated as a failure.

🔗 API Endpoints
---------------

[](#-api-endpoints)

### Webhook

[](#webhook)

The package automatically includes a webhook endpoint:

- **Endpoint**: `POST /api/webhooks/mailtrap`
- **Route name**: `webhooks.mailtrap`

The webhook is automatically registered and accepts external calls from Mailtrap.

🛠️ Development
--------------

[](#️-development)

This package is actively developed with focus on:

- Performance optimization
- Comprehensive email validation
- Automatic blocking of invalid emails
- Comprehensive mail logging
- Inbox UI and CLI tooling for inspecting and testing outgoing mail

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](LICENSE).

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance98

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~22 days

Recently: every ~31 days

Total

13

Last Release

9d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/24c445b7580e09ff72b8340d1423886148c4c8a249d0a828c98285109e7e5663?d=identicon)[darvis](/maintainers/darvis)

---

Top Contributors

[![ArvidDeJong](https://avatars.githubusercontent.com/u/7394837?v=4)](https://github.com/ArvidDeJong "ArvidDeJong (17 commits)")

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/darvis-mailtrap/health.svg)

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

###  Alternatives

[spatie/laravel-failed-job-monitor

Get notified when a queued job fails

1.1k2.8M4](/packages/spatie-laravel-failed-job-monitor)[statamic-rad-pack/runway

Eloquently manage your database models in Statamic.

135224.7k7](/packages/statamic-rad-pack-runway)[api-platform/laravel

API Platform support for Laravel

58171.5k14](/packages/api-platform-laravel)[ecotone/laravel

Ecotone for Laravel — CQRS, Event Sourcing, Sagas, Durable Workflows, and Outbox on top of Laravel Queue, via PHP attributes.

21318.6k3](/packages/ecotone-laravel)[duncanmcclean/statamic-cargo

Comprehensive e-commerce addon for Statamic. Build bespoke e-commerce sites without the complexity.

3416.9k](/packages/duncanmcclean-statamic-cargo)

PHPackages © 2026

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