mj-zana / communication
Email for Zana applications: messages, configured senders, Symfony Mailer transports and a recorder for tests
v2.41.0
2026-11-20 20:29 UTC
Requires
- php: ^8.5
- mj-zana/core: ^2.11
- symfony/mailer: ^7.4 || ^8.0
Requires (Dev)
- mj-zana/console: ^2.5
- mj-zana/database: ^2.0
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5
Suggests
- mj-zana/console: For the mail:test command
- mj-zana/database: To keep newsletter subscribers in the application's database
Provides
None
Conflicts
None
Replaces
None
- dev-main
- v2.41.0
- v2.40.0
- v2.39.0
- v2.38.0
- v2.37.0
- v2.36.0
- v2.35.0
- v2.34.0
- v2.33.0
- v2.32.0
- v2.31.0
- v2.30.0
- v2.29.0
- v2.28.0
- v2.27.0
- v2.26.0
- v2.25.0
- v2.24.0
- v2.23.0
- v2.22.0
- v2.21.0
- v2.20.0
- v2.19.0
- v2.18.0
- v2.17.0
- v2.16.0
- v2.15.0
- v2.14.0
- v2.13.0
- v2.12.0
- v2.11.0
- v2.10.0
- v2.9.0
- v2.8.0
- v2.7.0
- v2.6.0
- v2.5.0
- v2.4.0
- v2.3.0
- v2.2.0
- v2.1.0
This package is auto-updated.
Last update: 2026-12-03 08:36:47 UTC
README
Email for Zana applications: immutable messages, a configured sender, Symfony Mailer transports, and a recorder for tests.
composer require mj-zana/communication
Setup
Register CommunicationServiceProvider and configure the sender:
// config/mail.php return [ 'dsn' => 'smtp://user:pass@mail.example.com:587', // memory:// records instead (the default) 'from' => ['address' => 'website@example.com', 'name' => 'Example'], 'reply_to' => 'contact@example.com', // optional default Reply-To ];
Keep the DSN secret: set it from the environment, e.g.
APP_MAIL__DSN=smtp://....
Sending
$mailer->send(Message::create() ->to('contact@example.com') ->replyTo($visitor->email) ->subject('New message from the website') ->text($body));
Rules
- From comes from configuration. A message without
from()getsmail.from. Any other From must be listed inmail.allowed_from. A visitor's address goes in Reply-To, never in From: this keeps SPF and DMARC aligned and prevents spoofing. - Required: a recipient, a subject, and a text or HTML body.
- No header injection: line breaks in subjects, header values and names are refused.
- Transport failures become
MailException.
Testing
With mail.dsn: memory://, the mailer is a MailRecorder, which applies the
same rules:
$recorder = $container->get(MailRecorder::class); $this->assertCount(1, $recorder->sent(fn (Message $m): bool => $m->subject === 'Welcome'));
mj-zana/testing adds assertMailSent() and assertNoMailSent().
License
MIT