phpsoftbox/mailer

SMTP mailer for the PhpSoftBox framework

Maintainers

Package info

github.com/phpsoftbox/mailer

pkg:composer/phpsoftbox/mailer

Statistics

Installs: 20

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

dev-master 2026-03-05 13:16 UTC

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-объект.