PHPackages                             salines/cakephp-mail-interceptor - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. salines/cakephp-mail-interceptor

ActiveCakephp-plugin[Testing &amp; Quality](/categories/testing)

salines/cakephp-mail-interceptor
================================

CakePHP plugin to intercept and redirect outgoing emails to a specified address. Useful for development and staging environments.

v1.1.0(4mo ago)19MITPHPPHP &gt;=8.1CI passing

Since Jan 16Pushed 4mo agoCompare

[ Source](https://github.com/salines/cakephp-mail-interceptor)[ Packagist](https://packagist.org/packages/salines/cakephp-mail-interceptor)[ Docs](https://github.com/salines/cakephp-mail-interceptor)[ RSS](/packages/salines-cakephp-mail-interceptor/feed)WikiDiscussions master Synced today

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

CakePHP Mail Interceptor
========================

[](#cakephp-mail-interceptor)

[![CI](https://github.com/salines/cakephp-mail-interceptor/actions/workflows/ci.yml/badge.svg)](https://github.com/salines/cakephp-mail-interceptor/actions/workflows/ci.yml)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)[![CakePHP 5.x](https://camo.githubusercontent.com/a234092bcb3e553ee870fb29ec6351957a12a2266170f1d1fee3cda2cf545950/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f43616b655048502d352e782d7265642e737667)](https://cakephp.org)[![PHP 8.1+](https://camo.githubusercontent.com/7535257ca228724c93658bd52583d4e47a9bab02c356abf6e54c1d575f2151e6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e312532422d626c75652e737667)](https://php.net)

A CakePHP 5.x plugin that intercepts all outgoing emails and redirects them to a specified address. Perfect for development and staging environments where you want to test email functionality without sending emails to real users.

Why Use This Plugin?
--------------------

[](#why-use-this-plugin)

When developing or testing applications that send emails, you need a way to prevent emails from reaching real users. There are several approaches:

**Paid services** like Mailtrap or Mailosaur work great but require subscriptions and external dependencies.

**Local tools** like Mailpit, MailHog, or MailCatcher are excellent free alternatives, but they require local installation and configuration - which isn't always possible in shared hosting environments, Docker-less setups, or restricted infrastructure.

**This plugin** offers a zero-infrastructure solution:

- No additional services to install or maintain
- Works with your existing email transport (SMTP, Mailgun, SES, etc.)
- Simple configuration change - just wrap your existing transport
- Ideal for shared staging environments where installing local tools isn't an option
- Perfect for quick local development without setting up additional services

Features
--------

[](#features)

- Redirects all outgoing emails to a single address
- Preserves original recipient information in email headers (`X-Original-To`, `X-Original-Cc`, `X-Original-Bcc`)
- Adds configurable subject prefix to identify intercepted emails
- Optionally includes original recipients in subject line
- Logs all intercepted emails
- Works with any underlying CakePHP mail transport (SMTP, Mailgun, etc.)

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

[](#requirements)

- PHP 8.1+
- CakePHP 5.0+

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

[](#installation)

```
composer require salines/cakephp-mail-interceptor
```

Load the plugin in your `src/Application.php`:

```
use CakeMailInterceptor\CakeMailInterceptorPlugin;

public function bootstrap(): void
{
    parent::bootstrap();
    $this->addPlugin(CakeMailInterceptorPlugin::class);
}
```

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

[](#configuration)

Configure the transport in your `config/app_local.php`:

```
'EmailTransport' => [
    // Your real transport (used in production)
    'smtp' => [
        'className' => \Cake\Mailer\Transport\SmtpTransport::class,
        'host' => 'smtp.example.com',
        'port' => 587,
        'username' => 'user@example.com',
        'password' => 'secret',
        'tls' => true,
    ],

    // Intercept transport (used in development/staging)
    'default' => [
        'className' => \CakeMailInterceptor\Mailer\Transport\InterceptTransport::class,
        'transport' => 'smtp', // The underlying transport to use
        'to' => 'dev@example.com', // Where all emails will be redirected
        'subjectPrefix' => 'DEV', // Optional: tag for subject line
        'includeOriginalInSubject' => true, // Optional: add original recipients to subject
        'logInterceptions' => true, // Optional: log intercepted emails
    ],
],
```

Configuration Options
---------------------

[](#configuration-options)

OptionTypeDefaultDescription`transport`string*required*Name of the underlying transport to use for sending`to`string*required*Email address where all emails will be redirected`subjectPrefix`string`'INTERCEPTED'`Tag used in subject line prefix`includeOriginalInSubject`bool`true`Whether to include original recipients in subject prefix`logInterceptions`bool`true`Whether to log intercepted emailsHow It Works
------------

[](#how-it-works)

When an email is sent through the `InterceptTransport`:

1. Original recipients (To, Cc, Bcc) are saved to custom headers
2. All recipients are replaced with the configured `to` address
3. Subject is modified with prefix and/or original recipients
4. Email is sent using the underlying transport
5. Interception is logged (if enabled)

### Example

[](#example)

Original email:

- To: `user@example.com`
- Cc: `manager@example.com`
- Subject: `Your Order Confirmation`

Intercepted email:

- To: `dev@example.com`
- Subject: `[DEV: user@example.com] Your Order Confirmation`
- Header `X-Original-To`: `user@example.com`
- Header `X-Original-Cc`: `manager@example.com`

Recommended: Use Plus-Addressed Emails
--------------------------------------

[](#recommended-use-plus-addressed-emails)

We recommend using plus-addressed (subaddressed) emails for intercepted mail:

```
'to' => 'dev+projectname@example.com',
// or with environment identifier
'to' => 'dev+myapp-staging@example.com',
```

**Benefits of plus addressing:**

- **Easy filtering** - Create inbox rules to automatically sort intercepted emails by project or environment
- **Quick identification** - Instantly see which project/environment an email came from
- **Single inbox** - Use one email account for all projects without mixing emails
- **No extra accounts** - No need to create separate email addresses for each project

Most email providers support plus addressing, including Gmail, Outlook, ProtonMail, Fastmail, and others.

Environment-Based Configuration
-------------------------------

[](#environment-based-configuration)

A common pattern is to use the intercept transport only in non-production environments:

```
// config/app_local.php
'EmailTransport' => [
    'smtp' => [
        'className' => \Cake\Mailer\Transport\SmtpTransport::class,
        // ... smtp config
    ],
    'default' => env('APP_ENV') === 'production'
        ? [
            'className' => \Cake\Mailer\Transport\SmtpTransport::class,
            // ... production config
        ]
        : [
            'className' => \CakeMailInterceptor\Mailer\Transport\InterceptTransport::class,
            'transport' => 'smtp',
            'to' => 'dev@example.com',
        ],
],
```

Testing
-------

[](#testing)

```
composer install
composer test
```

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

License
-------

[](#license)

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

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance76

Regular maintenance activity

Popularity7

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

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 ~9 days

Total

5

Last Release

131d ago

### Community

Maintainers

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

---

Tags

testingmailemailcakephpdevelopmentcakephp-plugininterceptor

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/salines-cakephp-mail-interceptor/health.svg)

```
[![Health](https://phpackages.com/badges/salines-cakephp-mail-interceptor/health.svg)](https://phpackages.com/packages/salines-cakephp-mail-interceptor)
```

###  Alternatives

[cakephp/bake

Bake plugin for CakePHP

11212.0M202](/packages/cakephp-bake)[dereuromark/cakephp-ide-helper

CakePHP IdeHelper Plugin to improve auto-completion

1882.3M44](/packages/dereuromark-cakephp-ide-helper)[dereuromark/cakephp-tinyauth

A CakePHP plugin to handle user authentication and authorization the easy way.

131240.2k13](/packages/dereuromark-cakephp-tinyauth)[friendsofcake/fixturize

CakePHP Fixture classes to help increase productivity or performance

24520.3k1](/packages/friendsofcake-fixturize)[viraj/cakephp-integrated

Integration testing for CakePHP

1968.9k](/packages/viraj-cakephp-integrated)

PHPackages © 2026

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