New in Symfony 4.4: Notification Emails

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:

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.
Help the Symfony project!
As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.
Comments
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.
The "notification emails" also display their priority in a visible way and contain useful shortcuts such as the "action()" method to quickly add clickable buttons in the email message.
In any case, as mentioned above, these emails are intended to send notification to yourself, not to your customers.
This looks fine for stuff like "You've unlocked the first news comment in 2019 badge on symfony.com" or "Your reservation for the SymfonyCon will expire in 2 weeks." which could be send to customers, too?
Unknown "inky_to_html" filter
Is there something I am doing wrong?
Thanks!
this link points to the doc that explains how this very practical framework works
PHP Fatal error: Uncaught Symfony\Component\Mime\Exception\LogicException: A message must have a text or an HTML part or attachments. in /home/avrsites/websites/azvr.com/web/vendor/symfony/mime/Email.php:405
It works fine if I use ->html() or ->text(), but I was hoping I could use ->markdown()
I've tried installing all the suggested extra packages, but I still get the error.
I'm trying to override globally the theme of notification email without success...
Any clue ?
thanks