PHPackages                             w4msolutions/w4m-email-gateway - 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. w4msolutions/w4m-email-gateway

ActiveYii2-extension[Mail &amp; Notifications](/categories/mail)

w4msolutions/w4m-email-gateway
==============================

Yii2 mailer adapter that sends emails through the W4M Email Gateway service.

1.0.2(2mo ago)0100—10%proprietaryPHPPHP &gt;=8.1.0

Since May 14Pushed 2mo agoCompare

[ Source](https://github.com/W4MSOLUTIONS/w4m-email-gateway)[ Packagist](https://packagist.org/packages/w4msolutions/w4m-email-gateway)[ RSS](/packages/w4msolutions-w4m-email-gateway/feed)WikiDiscussions master Synced 1w ago

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

W4M Email Gateway Mailer
========================

[](#w4m-email-gateway-mailer)

Yii2 mailer adapter for sending emails through the W4M Email Gateway API.

Package
-------

[](#package)

- Name: `w4msolutions/w4m-email-gateway`
- Type: `yii2-extension`
- Namespace: `W4MSolutions\W4mEmailGateway`

Features
--------

[](#features)

- Drop-in compatible mailer component for current Yii2 mail usage.
- Keeps Yii compose/render/layout flow by extending `yii\symfonymailer\Mailer`.
- Supports existing `yii\symfonymailer\Message` calls used across the app.
- Sends payload to gateway `/send` endpoint with API key authentication.
- Converts regular attachments to gateway `attachments[]` payload.
- Rewrites inline CID embeds (for example `cid:image.jpg`) into `data:` URIs.
- Retries failed sends with incremental cooldown (default: 3 attempts, waits 1s then 3s).

Class and Function Reference
----------------------------

[](#class-and-function-reference)

### `W4MSolutions\W4mEmailGateway\Mailer`

[](#w4msolutionsw4memailgatewaymailer)

Main Yii mailer component.

- `init()` initializes default collaborators (`GatewayPayloadBuilder`, `GatewayClient`).
- `sendMessage($message)` validates config, maps payload, and executes retry-aware delivery.
- `sendWithRetry(array $payload)` runs delivery attempts with incremental cooldown.
- `sendPayload(array $payload)` performs one HTTP call through `GatewayClient`.
- `waitBeforeRetry(int $seconds)` sleeps between retries (override-friendly for tests).

### `W4MSolutions\W4mEmailGateway\GatewayPayloadBuilder`

[](#w4msolutionsw4memailgatewaygatewaypayloadbuilder)

Converts `yii\symfonymailer\Message` into gateway JSON payload.

- `build(Message $message)` maps recipients, subject/body, from/from\_name, reply\_to, attachments.
- `normalizeAddressList(...)` and `extractPrimaryAddressAndName(...)` standardize address data.
- `buildAttachmentPayload(...)` base64-encodes attachment data for gateway transport.

### `W4MSolutions\W4mEmailGateway\CidEmbedRewriter`

[](#w4msolutionsw4memailgatewaycidembedrewriter)

Makes inline embedded images compatible with gateway body-only HTML transport.

- `rewrite(string $html, array $attachments)` replaces `cid:` references with `data:` URIs.

### `W4MSolutions\W4mEmailGateway\GatewayClient`

[](#w4msolutionsw4memailgatewaygatewayclient)

HTTP transport client.

- `postJson(...)` sends request using cURL (preferred) or stream fallback.

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

[](#configuration)

This is the full configuration array for the mailer component with all options:

```
'components' => [
    'mailer' => [
        'class' => \W4MSolutions\W4mEmailGateway\Mailer::class,
        'viewPath' => '@common/mail',
        'gatewayUrl' => 'http://mail-gateway.local',
        'gatewayApiKey' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
        'authHeaderName' => 'Authorization', // Optional, default: 'Authorization'
        'authHeaderPrefix' => '', // Optional, default: ''
        'sendPath' => '/send', // Optional, default: '/send'
        'requestTimeout' => 15, // Optional, default: 15 seconds
        'maxRetries' => 3, // Optional, default: 3
        'retryInitialDelaySeconds' => 1, // Optional, default: 1
        'retryDelayIncrementSeconds' => 2, // Optional, default: 2
        'useFileTransport' => true, // default: true
    ],
],
```

Retry Behavior
--------------

[](#retry-behavior)

Default retry flow is:

1. Attempt 1 immediately.
2. If it fails, wait 1 second.
3. Attempt 2.
4. If it fails, wait 3 seconds (1 + 2).
5. Attempt 3.

You can tune this with:

- `maxRetries`
- `retryInitialDelaySeconds`
- `retryDelayIncrementSeconds`

Running Tests (Docker)
----------------------

[](#running-tests-docker)

Run tests in a dedicated container from this package folder.

### Required Tools

[](#required-tools)

- Docker Engine
- Docker Compose v2 (`docker compose`)

All commands below are executed from the package root.

### Run All Package Tests

[](#run-all-package-tests)

```
docker compose run --rm tests
```

### Run One Test File (Optional)

[](#run-one-test-file-optional)

```
docker compose run --rm tests sh docker/run-tests.sh tests/unit/MailerRetryTest.php
```

### Run One Test Method (Optional)

[](#run-one-test-method-optional)

```
docker compose run --rm tests sh docker/run-tests.sh tests/unit/MailerRetryTest.php --filter testSendMessageRetriesUntilSuccess
```

### Build or Rebuild the Test Image (Optional)

[](#build-or-rebuild-the-test-image-optional)

```
docker compose build
```

### Open a Shell in the Test Container (Optional)

[](#open-a-shell-in-the-test-container-optional)

```
docker compose run --rm tests bash
```

### Notes About the Standalone Setup

[](#notes-about-the-standalone-setup)

- `docker-compose.yml` and `Dockerfile` live inside this package and do not depend on the parent project.
- `docker/run-tests.sh` installs Composer dependencies automatically when `vendor/autoload.php` is missing.
- A Docker named volume (`composer-cache`) is used to speed up repeated Composer installs.

Notes
-----

[](#notes)

- The gateway schema documents `to`, `cc`, `bcc`, `subject`, `body`, `attachments`, `from_name`, and `reply_to`.
- This adapter also forwards a `from` field when available.
- If `useFileTransport` is true, Yii saves `.eml` files and skips gateway delivery.

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance86

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity44

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

Total

3

Last Release

71d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/170144652?v=4)[W4MSOLUTIONS](/maintainers/W4MSOLUTIONS)[@W4MSOLUTIONS](https://github.com/W4MSOLUTIONS)

---

Top Contributors

[![w4m-nelsondias](https://avatars.githubusercontent.com/u/150206383?v=4)](https://github.com/w4m-nelsondias "w4m-nelsondias (4 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/w4msolutions-w4m-email-gateway/health.svg)

```
[![Health](https://phpackages.com/badges/w4msolutions-w4m-email-gateway/health.svg)](https://phpackages.com/packages/w4msolutions-w4m-email-gateway)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.2k](/packages/craftcms-cms)[skeeks/cms

SkeekS CMS — control panel and tools based on php framework Yii2

13725.8k63](/packages/skeeks-cms)[loveorigami/yii2-notification-wrapper

This module for renders a message from session flash (with ajax, pjax support and etc.)

76206.2k5](/packages/loveorigami-yii2-notification-wrapper)

PHPackages © 2026

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