https://github.com/phpnomad/email
Email strategy interfaces for sending mail through any backend
https://github.com/phpnomad/email
email framework mail php phpnomad platform-agnostic
Last synced: 16 days ago
JSON representation
Email strategy interfaces for sending mail through any backend
- Host: GitHub
- URL: https://github.com/phpnomad/email
- Owner: phpnomad
- License: mit
- Created: 2024-04-18T22:25:51.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2026-04-10T02:10:34.000Z (about 2 months ago)
- Last Synced: 2026-04-14T11:13:36.162Z (about 2 months ago)
- Topics: email, framework, mail, php, phpnomad, platform-agnostic
- Language: PHP
- Homepage: https://phpnomad.com
- Size: 77.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# phpnomad/email
[](https://packagist.org/packages/phpnomad/email)
[](https://packagist.org/packages/phpnomad/email)
[](https://packagist.org/packages/phpnomad/email)
[](https://packagist.org/packages/phpnomad/email)
`phpnomad/email` defines the contract PHPNomad applications use to send transactional mail. It contains a single strategy interface, `EmailStrategy`, and a failure exception. Concrete sending lives in a separate integration package, so your application code depends on the contract rather than on a specific mailer. Swap the strategy in your bootstrapper and the rest of your code stays the same. The built-in implementation is [`phpnomad/php-mail-integration`](https://packagist.org/packages/phpnomad/php-mail-integration), which sends through PHP's `mail()` function. Anything else (SMTP, a third-party API, a queued background worker) drops in by writing another class that implements the interface.
## Installation
```bash
composer require phpnomad/email
```
You will also need a strategy implementation. Install `phpnomad/php-mail-integration` for the default, or provide your own class that implements `EmailStrategy`.
## Quick Start
Inject `EmailStrategy` wherever you send mail, then call `send()` and handle `EmailSendFailedException`.
```php
emailStrategy->send(
[$recipient],
'Your account is ready',
$body,
['Content-Type: text/html; charset=UTF-8']
);
} catch (EmailSendFailedException $e) {
// Log and continue, or rethrow depending on your policy.
}
}
}
```
## Overview
- `EmailStrategy` interface with a single `send(array $to, string $subject, string $body, array $headers): void` method
- `EmailSendFailedException` thrown by strategies when delivery fails
- A backend-agnostic contract your application depends on instead of a specific mailer
- Pairs with `phpnomad/php-mail-integration` for PHP's built-in `mail()` function, or any custom strategy you write
## Documentation
Full PHPNomad documentation is at [phpnomad.com](https://phpnomad.com).
## License
MIT. See [LICENSE.txt](LICENSE.txt).