Mail
Raxos Mail is a small mailing library built around a single MailerInterface contract. You compose a message with plain immutable value objects (Mail, Sender, Recipient, Attachment), then hand it to one of three ready made providers: Mailgun, Postmark or SMTP. Because every provider accepts the same Mail envelope, swapping one for another is just a matter of instantiating a different class. Nothing else in your code needs to change.
Alongside the sending pipeline, the package ships an Email value object that validates and splits an address into its parts, and an EmailSuggester that spots likely typos in a domain and proposes corrections.
Highlights
MailerInterfaceOne send() contract shared by the Mailgun, Postmark and SMTP providers.MailAn immutable envelope bundling subject, bodies, sender, recipients and attachments.EmailA validated address value object that parses username, domain and an optional plus tag.EmailSuggesterDetects likely typos in a domain and proposes corrected addresses.Explore by category
- Composing a mail: the
Mailenvelope and its building blocks,Sender,Recipient,RecipientTypeandAttachment. - Sending mail: the
MailerInterfacecontract, the three built in providers and how failures surface. - Email addresses and suggestions: parsing and validating addresses with
Email, and detecting typos withEmailSuggester.
Quick example
php
<?php
declare(strict_types=1);
use Raxos\Mail\{Mail, Postmark, Recipient, Sender};
$mail = new Mail(
subject: 'Welcome!',
html: '<p>Thanks for signing up.</p>',
text: 'Thanks for signing up.',
sender: new Sender('hello@example.com', 'Example'),
recipients: [
new Recipient('user@example.com', 'Jane Doe'),
],
);
$mailer = new Postmark(apiKey: 'server-token');
$mailer->send($mail);Installation
Install the package with Composer. See installation for the required PHP version and dependencies.
shell
composer require raxos/mail