Skip to content

Postal

A modern email library for CodeIgniter 4.

Write a message once and send it through SMTP, Amazon SES, Resend, sendmail or a failover chain. You choose the provider in config, not code. Existing service('email') calls keep working, so you can adopt Postal one step at a time.

composer require myth/postal

Requires PHP 8.2+ and CodeIgniter 4.7+. See Installation for extensions and configuration.

See it in action

<?php

namespace App\Mails;

use Myth\Postal\Mailable;

class Welcome extends Mailable
{
    public function __construct(private readonly string $address)
    {
        parent::__construct();
    }

    protected function build(): void
    {
        $this->from('hello@example.com', 'Acme')
            ->to($this->address)
            ->subject('Welcome aboard')
            ->markdown('emails/welcome');
    }
}

$result = (new Welcome('user@example.com'))->send();
<?php

use Myth\Postal\Email;

$email = (new Email())
    ->from('hello@example.com', 'Acme')
    ->to('user@example.com')
    ->subject('Welcome aboard')
    ->html('<p>Glad to have you with us.</p>');

$result = service('mailer')->send($email);

Either way, send() returns a SendResult instead of a bare bool:

<?php

if (! $result->success) {
    log_message('error', 'Welcome email failed: ' . $result->error);
}

Out of the box Postal's default mailer discards every message, so nothing is sent by accident. The Quick Start sets up a mailer in a few lines.

Why Postal

Where to go next

  • New to Postal?


    Install, configure a mailer and send your first Mailable in the Quick Start.

  • Already using CI4's Email?


    Move over in stages, without rewriting your app, with Migrating from CI4's Email.

  • Looking something up?


    Every method and setting is in the reference: Email, SendResult and Config\Mailer.

  • Want the big picture?


    How Postal Works explains mailers, transports and what happens during a send.

Support Postal

Postal is free and open source, built and maintained by Lonnie Ezell. If it saves you time, please consider sponsoring its development on GitHub. Sponsorship helps fund new features, fixes and these docs.

Sponsor on GitHub