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

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

ronald2wing/laravel-mailtrap
============================

Laravel mail transport for the Mailtrap Email Sending API

1.0.0(2mo ago)1131MITPHPPHP ^8.3CI passing

Since Apr 27Pushed 2mo agoCompare

[ Source](https://github.com/ronald2wing/Laravel-Mailtrap)[ Packagist](https://packagist.org/packages/ronald2wing/laravel-mailtrap)[ GitHub Sponsors](https://github.com/sponsors/ronald2wing)[ RSS](/packages/ronald2wing-laravel-mailtrap/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (7)Versions (2)Used By (0)

Laravel Mailtrap Driver
=======================

[](#laravel-mailtrap-driver)

[![Latest Version on Packagist](https://camo.githubusercontent.com/3f14cdd0b325d45dcf8d2ae15c17396c8198b164274206b049eef7f8c321533f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726f6e616c643277696e672f6c61726176656c2d6d61696c747261702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ronald2wing/laravel-mailtrap)[![Total Downloads](https://camo.githubusercontent.com/8ab6aa28027d6a925d722f829adf288755c20dee392df1a62114b62a61d5e3d3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726f6e616c643277696e672f6c61726176656c2d6d61696c747261702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ronald2wing/laravel-mailtrap)[![PHP Version](https://camo.githubusercontent.com/9464538c8d3f0a64731318c80cc93f69628bd4d6eb614c517463cc21b13c691d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f726f6e616c643277696e672f6c61726176656c2d6d61696c747261702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ronald2wing/laravel-mailtrap)[![License](https://camo.githubusercontent.com/960c41aad99412a466814140c870865c096d68ff7fcd51c1fd626be05c254166/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f726f6e616c643277696e672f6c61726176656c2d6d61696c747261702e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![GitHub Actions](https://camo.githubusercontent.com/514f7f6c82a4fd161c9ab8662cf78f19748e5fcce0c12831be41d9862f25ad6c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f726f6e616c643277696e672f6c61726176656c2d6d61696c747261702f7068702e796d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://github.com/ronald2wing/Laravel-Mailtrap/actions)[![Codecov](https://camo.githubusercontent.com/44c9f93895d16dcab52a3affc83784420944e7d24e230b99b32b8ebe1b06069d/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f726f6e616c643277696e672f6c61726176656c2d6d61696c747261703f7374796c653d666c61742d737175617265)](https://codecov.io/gh/ronald2wing/laravel-mailtrap)

A Laravel mail transport for the [Mailtrap Email Sending](https://mailtrap.io/email-sending) API. Adds a `mailtrap` transport that works with Laravel's native `Mail` facade — supporting attachments, CC/BCC, Reply-To, categories, templates, custom headers, custom variables, HTML/plain-text, and multiple accounts.

- [Requirements](#requirements)
- [Installation](#installation)
- [Configuration](#configuration)
    - [Environment variables](#environment-variables)
    - [Laravel mail config](#laravel-mail-config)
    - [Config reference](#config-reference)
- [Usage](#usage)
    - [Categories](#categories)
    - [Templates](#templates)
    - [Attachments](#attachments)
    - [CC, BCC, Reply-To](#cc-bcc-reply-to)
    - [Custom headers](#custom-headers)
    - [HTML and plain text](#html-and-plain-text)
- [Endpoints](#endpoints)
    - [Transactional (default)](#transactional-default)
    - [Bulk](#bulk)
    - [Sandbox (Email Testing)](#sandbox-email-testing)
- [Custom base URL](#custom-base-url)
- [HTTP options](#http-options)
- [Multiple accounts](#multiple-accounts)
- [Testing](#testing)
- [Troubleshooting](#troubleshooting)
- [Contributing](#contributing)
- [Security](#security)
- [License](#license)

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

[](#requirements)

- PHP 8.3+
- Laravel 10, 11, 12, or 13
- PHP extension: curl (required by Guzzle/Laravel HTTP client)

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

[](#installation)

```
composer require ronald2wing/laravel-mailtrap
```

The service provider auto-registers via Laravel package discovery — no manual setup needed.

Publish the config file:

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

Configuration
-------------

[](#configuration)

### Environment variables

[](#environment-variables)

VariableRequiredDefaultDescription`MAILTRAP_TOKEN`Yes—Your Mailtrap API token`MAILTRAP_ENDPOINT`No`transactional``transactional`, `bulk`, or `sandbox``MAILTRAP_INBOX_ID`With `sandbox`—Inbox ID for Email Testing. Must be a positive integer.`MAILTRAP_BASE_URL`No(endpoint default)Override the API URL for proxies or staging.### Laravel mail config

[](#laravel-mail-config)

Set the default mailer and register the transport in `config/mail.php`:

```
'default' => env('MAIL_MAILER', 'mailtrap'),

'mailers' => [
    'mailtrap' => [
        'transport' => 'mailtrap',
    ],
],
```

### Config reference

[](#config-reference)

```
// config/mailtrap.php
use Ronald2Wing\LaravelMailtrap\MailtrapEndpoint;

return [
    'token'    => env('MAILTRAP_TOKEN'),

    'endpoint' => env('MAILTRAP_ENDPOINT', MailtrapEndpoint::Transactional->value),

    'inbox_id' => ($inboxId = env('MAILTRAP_INBOX_ID')) !== null
                   ? (int) $inboxId
                   : null,

    'base_url' => env('MAILTRAP_BASE_URL'),

    'http'     => [
        'connect_timeout' => 10,
        'timeout'         => 30,
    ],
];
```

Usage
-----

[](#usage)

Send mail with the `Mail` facade — identical to any other Laravel driver:

```
use Illuminate\Support\Facades\Mail;

Mail::to('user@example.com')->send(new WelcomeEmail());
```

### Categories

[](#categories)

Add an `X-Mailtrap-Category` header to segment analytics in Mailtrap. Multiple categories are comma-separated.

```
class WelcomeEmail extends Mailable
{
    public function envelope(): Envelope
    {
        return new Envelope(
            subject: 'Welcome',
        );
    }

    public function content(): Content
    {
        return new Content(
            view: 'emails.welcome',
        );
    }

    public function headers(): Headers
    {
        return new Headers(
            text: [
                'X-Mailtrap-Category' => 'onboarding',
            ],
        );
    }
}
```

Comma-separated for multiple:

```
public function headers(): Headers
{
    return new Headers(
        text: ['X-Mailtrap-Category' => 'newsletter,marketing,weekly'],
    );
}
```

### Templates

[](#templates)

Send through Mailtrap templates using custom headers:

```
class WelcomeEmail extends Mailable
{
    public function headers(): Headers
    {
        return new Headers(
            text: [
                'X-Mailtrap-Template-Uuid'      => 'abc-123-def',
                'X-Mailtrap-Template-Variables' => json_encode([
                    'name'    => 'John',
                    'company' => 'Acme',
                ]),
                'X-Mailtrap-Custom-Variables'   => json_encode([
                    'plan' => 'pro',
                ]),
            ],
        );
    }
}
```

- `X-Mailtrap-Template-Variables` — values injected into the template. Must be valid JSON.
- `X-Mailtrap-Custom-Variables` — arbitrary key-value data attached to the send, also JSON.

### Attachments

[](#attachments)

```
class InvoiceEmail extends Mailable
{
    public function attachments(): array
    {
        return [
            Attachment::fromPath('/path/to/invoice.pdf')
                ->as('invoice.pdf')
                ->withMime('application/pdf'),
            Attachment::fromPath('/path/to/terms.pdf'),
        ];
    }
}
```

Embedded (inline) images are also supported:

```
$cid = $this->embed('/path/to/logo.png');

return $this->view('emails.newsletter')
    ->with('logoCid', $cid);
```

### CC, BCC, Reply-To

[](#cc-bcc-reply-to)

```
Mail::send('emails.announcement', $data, function ($message) {
    $message->to('team@example.com')
        ->cc(['manager@example.com', 'lead@example.com'])
        ->bcc('archive@example.com')
        ->replyTo('noreply@example.com', 'No Reply')
        ->subject('Announcement');
});
```

Multiple Reply-To addresses are joined with `,` per RFC 5322.

### Custom headers

[](#custom-headers)

Arbitrary headers are forwarded in the payload:

```
Mail::send('emails.order', $data, function ($message) {
    $message->to('customer@example.com')
        ->header('X-Priority', '1')
        ->header('X-Order-ID', 'ORD-12345')
        ->subject('Order Confirmation');
});
```

### HTML and plain text

[](#html-and-plain-text)

Provide both HTML and plain-text versions:

```
class WelcomeEmail extends Mailable
{
    public function content(): Content
    {
        return new Content(
            view: 'emails.welcome',       // HTML
            text: 'emails.welcome-text',  // plain-text fallback
        );
    }
}
```

Endpoints
---------

[](#endpoints)

The `endpoint` config key determines which Mailtrap API is used.

### Transactional (default)

[](#transactional-default)

One-off emails — notifications, password resets, receipts.

```
'endpoint' => 'transactional',
```

API: `https://send.api.mailtrap.io/api/send`

### Bulk

[](#bulk)

High-volume sending via the bulk API.

```
'endpoint' => 'bulk',
```

API: `https://bulk.api.mailtrap.io/api/send`

### Sandbox (Email Testing)

[](#sandbox-email-testing)

Test emails within Mailtrap's Email Testing product. Requires an `inbox_id`.

```
'endpoint'  => 'sandbox',
'inbox_id'  => env('MAILTRAP_INBOX_ID'),
```

API: `https://sandbox.api.mailtrap.io/api/send/{inbox_id}`

Custom base URL
---------------

[](#custom-base-url)

Override the API URL for proxy environments or staging setups. The `endpoint` still controls authentication behavior — `base_url` only changes the destination:

```
'base_url' => 'https://custom-proxy.example.com',
```

HTTP options
------------

[](#http-options)

Any Guzzle-compatible request option can be set under the `http` key. Defaults are `connect_timeout: 10` and `timeout: 30`.

```
'http' => [
    'connect_timeout' => 10,
    'timeout'         => 30,
    'verify'          => false,          // disable SSL verification (dev only)
    'proxy'           => 'http://proxy:8080',
],
```

Multiple accounts
-----------------

[](#multiple-accounts)

Define sub-configurations in `config/mailtrap.php` and reference them via dot-notation from mailers. Sub-configs inherit top-level defaults (endpoint, base\_url, HTTP options) and override only the keys you specify:

```
// config/mailtrap.php
return [
    'token'         => env('MAILTRAP_TOKEN'),
    'endpoint'      => env('MAILTRAP_ENDPOINT', MailtrapEndpoint::Transactional->value),

    'transactions' => [
        'token'    => env('MAILTRAP_TOKEN_TRANSACTIONS'),
        'endpoint' => 'transactional',
        'http'     => ['timeout' => 60],
    ],

    'marketing' => [
        'token'    => env('MAILTRAP_TOKEN_MARKETING'),
        'endpoint' => 'bulk',
    ],

    'sandbox' => [
        'token'    => env('MAILTRAP_TOKEN_SANDBOX'),
        'endpoint' => 'sandbox',
        'inbox_id' => (int) env('MAILTRAP_INBOX_ID'),
    ],
];
```

```
// config/mail.php
'mailers' => [
    'mailtrap_transactions' => [
        'transport' => 'mailtrap',
        'config'    => 'mailtrap.transactions',
    ],

    'mailtrap_marketing' => [
        'transport' => 'mailtrap',
        'config'    => 'mailtrap.marketing',
    ],

    'mailtrap_sandbox' => [
        'transport' => 'mailtrap',
        'config'    => 'mailtrap.sandbox',
    ],
];
```

Testing
-------

[](#testing)

Use `Mail::fake()` as usual — no transport swap is needed.

```
Mail::fake();

// exercise your application...

Mail::assertSent(WelcomeEmail::class, function ($mail) use ($user) {
    return $mail->hasTo($user->email)
        && $mail->hasHeader('X-Mailtrap-Category', 'onboarding');
});
```

Troubleshooting
---------------

[](#troubleshooting)

ErrorSolution`Mailtrap API token cannot be empty`Set `MAILTRAP_TOKEN` in `.env`.`Unknown Mailtrap endpoint "...".``endpoint` must be one of: `transactional`, `bulk`, `sandbox`.`Sandbox endpoint requires an inbox_id`Set `MAILTRAP_INBOX_ID` to a valid inbox ID.`inbox_id must be a positive integer`Pass the inbox ID as an integer, or use the `(int)` cast from `env()`.`cURL error 60: SSL certificate problem`Update CA certificates, or set `http.verify` to a CA bundle path.`Connection timed out`Increase `http.timeout` and `http.connect_timeout`.`Mailtrap API returned HTTP 4xx/5xx`Verify your API token. Switch to the `log` mailer temporarily to inspect the raw payload.Contributing
------------

[](#contributing)

```
git clone https://github.com/ronald2wing/laravel-mailtrap.git
cd laravel-mailtrap
composer install
```

### Quality checks

[](#quality-checks)

CommandPurpose`composer run test`PHPUnit with Clover + HTML coverage → `coverage/``composer run lint`Check formatting with Pint (read-only)`composer run format`Apply formatting with Pint`composer run analyse`PHPStan level 8`composer run check`lint → analyse → testSecurity
--------

[](#security)

- Never commit API tokens.
- Always enable SSL verification in production.
- Validate file types and sizes before attaching user-supplied content.

License
-------

[](#license)

MIT. See [LICENSE](LICENSE) for details.

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance88

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

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

Unknown

Total

1

Last Release

60d ago

### Community

Maintainers

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

---

Top Contributors

[![ronald2wing](https://avatars.githubusercontent.com/u/16713673?v=4)](https://github.com/ronald2wing "ronald2wing (3 commits)")

---

Tags

laravellaravel-mailermailtraplaravelemailtransportmailtrap

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[propaganistas/laravel-disposable-email

Disposable email validator

6012.9M7](/packages/propaganistas-laravel-disposable-email)[jurager/teams

Laravel package to manage team functionality and operate with user permissions.

23720.8k](/packages/jurager-teams)[notebrainslab/filament-email-templates

A powerful and flexible Email Template Management plugin for Filament v4 and v5.

121.1k](/packages/notebrainslab-filament-email-templates)

PHPackages © 2026

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