phpsoftbox / mailer
SMTP mailer for the PhpSoftBox framework
dev-master
2026-03-05 13:16 UTC
Requires
- php: ^8.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.93
- phpsoftbox/cli-app: dev-master
- phpsoftbox/cs-fixer: ^1.1.0
- phpunit/phpunit: ^11.2
This package is auto-updated.
Last update: 2026-03-05 13:16:17 UTC
README
SMTP-отправка для PhpSoftBox, совместимая с компонентом Notifications.
Быстрый старт
use PhpSoftBox\Mailer\Smtp\SmtpClient; use PhpSoftBox\Mailer\Smtp\SmtpClientConfig; use PhpSoftBox\Mailer\Transport\SmtpEmailTransport; use PhpSoftBox\Mailer\Transport\FileEmailTransport; use PhpSoftBox\Notifications\Email\EmailChannel; $config = new SmtpClientConfig( host: 'mailhog', port: 1025, username: null, password: null, encryption: 'none', helo: 'domain.local', ); $transport = new SmtpEmailTransport(new SmtpClient($config)); $channel = new EmailChannel($transport, /* markdown */ null, /* renderer */ null, 'no-reply@domain.local');
File transport
Для локальной отладки можно сохранять письма в файлы:
$transport = new FileEmailTransport(__DIR__ . '/var/mails', 'no-reply@domain.local');
MailHog
Для локальной отладки удобно использовать MailHog (SMTP + UI).
Сервис можно поднять через docker-compose:
mailhog: image: mailhog/mailhog ports: - "1025:1025" - "8025:8025"
UI доступен на http://localhost:8025.
EmailMessage layout
Для шаблонных email используйте template() и layout():
use PhpSoftBox\Mailer\Message\EmailMessage; $message = EmailMessage::create('Тема письма') ->template('email/content.phtml', ['name' => 'User']) ->layout('email/layout.phtml', ['title' => 'Тема письма']);
В template()/layout() можно передавать как массив, так и DTO-объект.