Download the PHP package maba/mail-renderer-bundle without Composer
On this page you can find all versions of the php package maba/mail-renderer-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package mail-renderer-bundle
Mail Renderer Bundle
Symfony bundle that collects some libraries together to make sending emails easier:
- Renders twig template to get subject and content of an email
- Converts HTML content to plain text if it's not available in template
- Sets default From email and name to message
- Gets CSS for mail messages using Assetic, if configured
- Inlines CSS inside HTML
styleattributes and/or adds<styles>tag - Sends message using swift mailer
Installation
Add via composer:
composer require maba/mail-renderer-bundle jimbojsb/emogrify:@dev
Register bundle:
Configure in config.yml:
css_assets node is optional, as is usage of Assetic.
Usage
Code:
Twig template:
That's it!
All CSS rules assigned to classes will be inlined into HTML as style attributes.
Extended usage
Templates
Only these blocks are parsed from template: subject, body_html and body_text.
subject and at least one of other two are required. Any other blocks or content in template is ignored.
If body_text is provided, it will be used as plain text version of mailer message.
Additionally toEmail variable is passed to the twig template, which equals to the given recipient.
I'd suggest to use single layout twig file, if there's defined structure in your mails. For example:
Styles
inline and imports values in css_assets configuration node take Assetic asset name, which you should configure
using Assetic configuration.
inline is used when applying CSS rules to message HTML result - style attributes are added to HTML nodes, which
would trigger appropriate CSS rules. This is needed as some email readers support neither <styles> nor <link>
(for example GMail).
imports is used to make <styles> tag with CSS contents in the mail message itself. This should be as short as
possible - usually only for rules that cannot be inlined, like this one:
That's why it's called imports in configuration.
Why <styles> instead of <link>? To avoid remote resource loading, which is also most commonly disabled by default.
Changing created message
Use createMessage instead of sendMessage with same parameters in renderer,
change or add any required fields and send with swift mailer manually.
All versions of mail-renderer-bundle with dependencies
symfony/framework-bundle Version ^2.3
twig/twig Version ~1.0
nickcernis/html-to-markdown Version ^2.2
jimbojsb/emogrify Version dev-master#5f323d2880e5df7de273c15e2a98e7c77a3cfba3
symfony/swiftmailer-bundle Version ^2.3
symfony/assetic-bundle Version ^2.6