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 driver for sending emails through Mailtrap.io Email Sending Service API

1.0.0(3mo ago)182MITPHPPHP ^8.2CI passing

Since Jan 20Pushed 3mo agoCompare

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

READMEChangelogDependencies (8)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/3aec307e07c8b8d80bc14ed9ca835d85f13fcaac4887368d5e1c049cf9c7efba/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f726f6e616c643277696e672f6c61726176656c2d6d61696c747261702f7068702e796d6c3f6272616e63683d6d61696e267374796c653d666c61742d737175617265)](https://github.com/ronald2wing/laravel-mailtrap/actions)[![Codecov](https://camo.githubusercontent.com/44c9f93895d16dcab52a3affc83784420944e7d24e230b99b32b8ebe1b06069d/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f726f6e616c643277696e672f6c61726176656c2d6d61696c747261703f7374796c653d666c61742d737175617265)](https://codecov.io/gh/ronald2wing/laravel-mailtrap)

A Laravel mail driver for sending emails through the [Mailtrap.io](https://mailtrap.io) Email Sending Service API. Seamlessly integrate Laravel with Mailtrap's sending API while using Laravel's familiar mail API.

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

[](#-features)

- **Easy Setup**: Simple configuration with Laravel's mail system
- **Full API Support**: Categories, attachments, CC/BCC, custom headers
- **Laravel Compatible**: Works with Laravel 10.x, 11.x, and 12.x
- **Clean Codebase**: Well-documented with comprehensive tests
- **Robust Error Handling**: Clear error messages and debugging
- **Email Analytics**: Mailtrap categories for tracking
- **UTF-8 Support**: Full international character support
- **Customizable**: Configurable API endpoints and HTTP client
- **High Performance**: Optimized payload construction and HTTP requests
- **Comprehensive Testing**: 27+ tests covering all features

📋 Requirements
--------------

[](#-requirements)

- PHP 8.2 or higher
- Laravel 10.x, 11.x, or 12.x
- GuzzleHTTP 7.0 or higher
- Required PHP extensions: curl, json, mbstring, openssl (recommended)

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

[](#-quick-start)

### 1. Install via Composer

[](#1-install-via-composer)

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

The package uses Laravel's auto-discovery, so the service provider will be registered automatically.

### 2. Configure Environment Variables

[](#2-configure-environment-variables)

Add the following to your `.env` file:

```
MAIL_MAILER=mailtrap
MAILTRAP_TOKEN=your_mailtrap_api_token_here
```

### 3. Configure Services

[](#3-configure-services)

Add the Mailtrap configuration to your `config/services.php` file:

```
'mailtrap' => [
    'token' => env('MAILTRAP_TOKEN', ''),

    // Optional: Custom API endpoint (for testing or custom deployments)
    // 'endpoint' => 'https://custom.api.mailtrap.io/api/send',

    // Optional: Guzzle HTTP client configuration
    // 'guzzle' => [
    //     'timeout' => 30,
    //     'connect_timeout' => 10,
    //     'verify' => true,
    // ],
],
```

### 4. Configure Mail Settings

[](#4-configure-mail-settings)

Update your `config/mail.php` file to use the Mailtrap transport:

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

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

    // ... other mailers (smtp, log, etc.)
],
```

🔑 Obtaining Your Mailtrap API Token
-----------------------------------

[](#-obtaining-your-mailtrap-api-token)

1. Log in to your [Mailtrap account](https://mailtrap.io)
2. Navigate to your sending domain settings
3. Go to the "API" or "Integration" section
4. Copy your API token
5. Add it to your `.env` file as `MAILTRAP_TOKEN`

📝 Usage
-------

[](#-usage)

### Basic Email Sending

[](#basic-email-sending)

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

// Send a basic email
Mail::to('recipient@example.com')
    ->send(new WelcomeEmail());

// Send with multiple recipients
Mail::to(['user1@example.com', 'user2@example.com'])
    ->cc('manager@example.com')
    ->bcc('admin@example.com')
    ->send(new AnnouncementEmail());
```

### Using Mailable Classes

[](#using-mailable-classes)

```
