maatify / email-delivery
Standalone email delivery module for rendering, queueing and sending emails.
Requires
- php: ^8.2
- ext-json: *
- ext-pdo: *
- maatify/crypto: ^1.0
- phpmailer/phpmailer: ^6.9 || ^7.0
- psr/log: ^3.0
- symfony/polyfill-mbstring: ^1.3
- twig/twig: ^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.94
- league/commonmark: ^2.9.1
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^11.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Maatify Email Delivery
A framework-independent PHP library for an encrypted email queue, Twig HTML rendering and SMTP transport through PHPMailer. Applications enqueue work; a separately run worker attempts delivery.
At publication update on 2026-11-23, 1.3.0 became the latest published release (published 2026-11-23 UTC).
Its release-qualified source is f72addfaff7da1813e2b1005bf706713512e375b; see the publication record
for CI, release-artifact and external Composer verification evidence.
Release artifact target: 1.3.0. Publication state at qualification: unpublished. The latest externally published version at qualification is 1.2.0, published on 2026-11-06 UTC and verified as an exact Composer dist installation. These facts preserve the historical qualification snapshot.
Start here
- Usage Guide and root examples
- Package Reference — canonical supported contract and complete API inventory
- Documentation map
- Idempotency and receipt reference — the complete keyed API contract
- Synthetic no-send recording — encrypted inert storage and bounded maintenance
- Install or upgrade the schema — fresh and existing installations differ
- Prepare the next release
- Examples, how-to guides, architecture book
- Security policy and security architecture description
Choose the enqueue contract
| Requirement | API | Result |
|---|---|---|
| Each call intentionally creates another job | EmailQueueWriterInterface::enqueue() / PdoEmailQueueWriter |
void; no request deduplication |
| Retrying one identified request must not create another job | IdempotentEmailQueueWriterInterface::enqueueOnce() / PdoIdempotentEmailQueue |
A committed receipt; different content on the same key conflicts |
| Record an inert request without any email job | SyntheticEmailRecorderInterface::record() / PdoSyntheticEmailStore |
Distinct synthetic record; never a delivery receipt |
| Observe an accepted keyed request | EmailEnqueueReceiptReaderInterface::find(namespace, key) |
Scoped receipt or null; no recipient/context returned |
Keyed enqueue atomically stores a job and its durable receipt. Repeating the same namespace/key and logical content returns the same receipt/job identity. It does not guarantee exactly-once SMTP or mailbox arrival. In 1.3.0, a job whose worker was interrupted after claiming it is claimed again once its processing lease expires, so it may be sent twice (at-least-once). Published 1.2.0 does not include that lease recovery behavior.
Public Runtime API
| Capability | Supported entry points |
|---|---|
| Per-call queue insertion | EmailQueueWriterInterface, PdoEmailQueueWriter |
| Keyed acceptance and scoped observation | IdempotentEmailQueueWriterInterface, EmailEnqueueReceiptReaderInterface, PdoIdempotentEmailQueue |
| Inert recording and trusted cleanup | SyntheticEmailRecorderInterface, SyntheticEmailMaintenanceInterface, PdoSyntheticEmailStore |
| Rendering | EmailRendererInterface, TwigEmailRenderer, payload/rendered DTOs |
| Explicit SMTP call | EmailTransportInterface, SmtpEmailTransport, EmailTransportConfigDTO |
| One processing batch | EmailQueueWorker |
The Package Reference owns the complete supported inventory, DTO fields, enum values, exceptions and behavioral boundaries. Internal helpers are not consumer API.
Installation and dependencies
composer require maatify/email-delivery:1.3.0
The exact 1.3.0 version is available from Packagist. Historical qualification instructions: At qualification, install
composer require maatify/email-delivery:1.2.0; use the exact 1.3.0 command above when 1.3.0 is available from Packagist.
The unpinned command composer require maatify/email-delivery resolves to the version Packagist offers at install time.
Version 1.3.0 requires PHP 8.2+, JSON and PDO, plus maatify/crypto, Twig, PHPMailer (6.9+ or 7), PSR-3 logging and
symfony/polyfill-mbstring (mb_strcut without the mbstring extension). Published 1.2.0 requires PHPMailer ^6.9
and does not declare the polyfill directly; these dependency changes are not part of 1.2.0.
The production keyed and synthetic storage paths use MySQL/MariaDB with pdo_mysql and the package-owned
SQL files. SQLite is used by legacy tests, not supported as keyed production storage.
Supply your application PDO, crypto provider/context provider, renderer, transport and logger through DI.
Monolog is not a package dependency.
Apply the schema installation/upgrade before adopting the keyed API. Do not run
all numbered SQL files on a fresh installation: the binding upgrade is for an existing legacy table.
The 1.3.0 worker claim index (005): fresh installs run 001, 002, then 005; legacy tables
without enqueue_receipt_id run 002, 003, then 005. If the installed schema already has the binding and
receipt table (whether from 001+002 or 002+003), apply only 005 and only when no equivalent claim index
exists. Optional 006 (also included in 1.3.0) indexes scoped batches; apply it after 005 only if you use them.
Synthetic recording uses an optional independent table and separate crypto domains. Its retention is explicitly configured by the consumer; cleanup is scheduled externally. It provides no constant-time or HTTP security guarantee. See the full contract.
Quick Usage
This function defines application wiring; including it does not connect or send mail. Its dependencies must already be configured. See the complete examples for construction, explicit scheduling, receipt lookup and worker composition.
use Maatify\EmailDelivery\Queue\DTO\EmailEnqueueReceiptDTO; use Maatify\EmailDelivery\Queue\DTO\EmailEnqueueRequestDTO; use Maatify\EmailDelivery\Queue\DTO\EmailQueuePayloadDTO; use Maatify\EmailDelivery\Queue\IdempotentEmailQueueWriterInterface; function queueWelcome( IdempotentEmailQueueWriterInterface $queue, string $authenticatedNamespace, string $stableRequestKey, string $recipient, string $name, ): EmailEnqueueReceiptDTO { return $queue->enqueueOnce(new EmailEnqueueRequestDTO( consumerNamespace: $authenticatedNamespace, requestKey: $stableRequestKey, entityType: 'user', entityId: null, recipientEmail: $recipient, payload: new EmailQueuePayloadDTO(['name' => $name], 'welcome', 'en'), senderType: 1, )); }
Persist the key and intended content in the caller; do not generate a new key on every retry. Namespace is a scope, not authentication. Derive it from the authenticated caller and keep PII/secrets out of keys. The reference defines canonical content, validation, transaction errors, indefinite receipt/key retention and recovery with the same key on a fresh connection.
Worker and delivery boundaries
EmailQueueWorker::processBatch() claims a bounded pending batch under row locks, commits the claim,
then decrypts/renders and calls the transport outside that transaction. Run it from your application's
supervised process using the worker guide.
New in 1.3.0: construct the worker with a connection factory, Closure(): PDO, so it can
replace a connection the server closed while a send was running. A processing row whose lease
expires (default 300 seconds, configurable) is claimed again; delivery is at-least-once. Worker connections
need exception error mode and autocommit enabled, and the claim index 005 keeps the claim's reads from
scanning the whole table. See the
processing lease and
ADR-012.
Version 1.3.0 adds processBatchByEntityType($entityType, $limit) for a worker dedicated to one entity type in a
shared queue; it takes, reclaims and sends only rows of that type, and locks only candidates of that type
(a candidate whose type changes before the lock is not taken, though it can stay locked until the claim
ends). Optional schema 006 keeps its reads fast behind a large backlog of other types. See
scoped batches.
Keyed jobs use database UTC for due/retry selection, retry deadlines and sent_at. NULL-token legacy
jobs retain local database NOW() and PHP-local retry calculation. The worker supports pre-binding
legacy tables and does not mutate the session timezone. Clock and failure details.
Development verification
composer validate --strict
composer test
composer analyse -- --memory-limit=512M
composer check:docs
composer check:examples
composer check:artifact
Without DB configuration, real-DB tests skip. CI is configured for PHP 8.2/8.3/8.4/8.5 with required MySQL
integration tests and an additional no-DB skip check. For a disposable dedicated database ending in
_test, set EMAIL_DELIVERY_IT_DSN, EMAIL_DELIVERY_IT_USER, EMAIL_DELIVERY_IT_PASS and
EMAIL_DELIVERY_IT_REQUIRED=1. Tests own/drop their queue tables; never target an application database.
See the release checklist for evidence and documentation checks.
License
This library is licensed under the MIT License. Vulnerability reports follow SECURITY.md.
Author
Engineered by Mohamed Abdulalim (@megyptm)
Backend Lead & Technical Architect
https://www.maatify.dev
Built with ❤️ by Maatify.dev — Unified Ecosystem for Modern PHP Libraries