2021-07-05 811次浏览

First releases of mailer package and its SwiftMailer adapter were released.

The mailer package provides the content composition functionality, and a basic interface for sending emails. Actual mail sending is provided by separate interchangeable packages.

The following code can be used to send an email:

/**
 * @var \Yiisoft\Mailer\MailerInterface $mailer
 */

$message = $mailer->compose()
    ->withFrom('from@domain.com')
    ->withTo('to@domain.com')
    ->withSubject('Message subject')
    ->withTextBody('Plain text content')
    ->withHtmlBody('<b>HTML content</b>')
;
$mailer->send($message);

Out of the box the package profiles a file mailer that, instead of actually sending an email, writes its contents into a file. There is also SwiftMailer-based official driver available as a separate package that actually can send emails.