trail / mail
A mailer addon for trail
dev-main / 0.1.x-dev
2026-09-30 21:20 UTC
Requires
- php: >=8.4
- ext-openssl: *
- trail/framework: ^0.1
Requires (Dev)
None
Suggests
- trail/queue: send mail from a worker with app.mail.queue
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-30 21:21:04 UTC
README
A mailer addon for trail framework
install
composer require trail/mail
Needs openssl
config
// app.php
'mail' => [
'dsn' => App::env('MAIL_DSN'),
'from' => 'hi@example.com',
'name' => 'Example',
],
# .env
MAIL_DSN="smtps://user%40example.com:password@smtp.example.com:465"
Provider gives a host and a port. Use the scheme that matches the port:
- port 465:
smtps://user:pass@host:465 - port 587:
smtp://user:pass@host:587 @,:, and/in the user or password need url encoding (%40,%3A,%2F)- no dsn? dev mode logs every letter. prod logs a warning
sending
use Trail\Mail\Letters\Letter;
use Trail\Mail\Outbox\Outbox;
public function __construct(private Outbox $outbox) {}
$this->outbox->send(new Letter(
to: 'wat@example.com',
subject: 'me innit',
text: View::make('mail/welcome', ['user' => $user]),
html: View::make('mail/welcome-html', ['user' => $user]), // optional
replyTo: 'oops@example.com', // optional
cc: ['also@example.com'], // optional
bcc: ['shh@example.com'], // optional
));
- one
toper letter.ccandbcctake lists - bcc doesnt show up in messages
- addresses get checked
- subjects and names are safe
- if the server says no it yells
Undeliveredwith what the server said
Sending happens during request, so there might be a delay
queue it
Add trail/queue and you can use a worker instead
'mail' => [
'dsn' => App::env('MAIL_DSN'),
'from' => 'hi@example.com',
'queue' => true,
],
send()pushes a job,- failed sends get retried by queue,
Undeliveredends up inqueue::failed - letters sit in
queue_jobsuntil sent - no worker kills mail.
app.queue.runNowin config will send right away. good for local dev
your own outbox
Bind anything that implements Outbox in a site addon
$box->bind(Outbox::class, MyOutbox::class);
For testing you have Pigeonhole, which keeps letters in $letters instead of sending them
$box->bind(Outbox::class, Pigeonhole::class);
cli
trail/trail mail::test stuff@example.com
not done yet
- attachments