Fabien Potencier
Contributed by Fabien Potencier in #33605

The Mime component was introduced in Symfony 4.3 to help you create email messages. In Symfony 4.4 we've improved it with notification emails. These emails are standardized messages used to send notifications to yourself (e.g. a new user signed up, some invoice was paid, etc.)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use Symfony\Bridge\Twig\Mime\NotificationEmail;

$email = (new NotificationEmail())
    ->from('fabien@example.com')
    ->to('fabien@example.org')
    ->subject('My first notification email via Symfony')
    ->markdown(<<<EOF
        There is a **problem** on your website, you should investigate it
        right now. Or just wait, the problem might solves itself automatically,
        we never know.
        EOF
    )
    ->action('More info?', 'https://example.com/')
    ->importance(NotificationEmail::IMPORTANCE_HIGH)
;

Now, use the Mailer component to actually send this message and you'll see something like this in your email client:

A notification email created with Symfony Mime component

Notification emails are already styled with a responsive design based on Foundation for Emails 2, but you can override the theme globally or per email.

Published in #Living on the edge