fullpipe / email-template-bundle
Keep email templates in repo and in order
Installs: 7
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=5.3.3
- html2text/html2text: ~2.0
- symfony/framework-bundle: ~2.3
- symfony/twig-bundle: ~2.3
- tijsverkoyen/css-to-inline-styles: ~1.5
This package is auto-updated.
Last update: 2024-10-27 00:58:38 UTC
README
Keep email templates in repo and in order.
Installation
First you need to add fullpipe/email-template-bundle
to composer.json
:
{ "require": { "fullpipe/email-template-bundle": "dev-master" } }
You also have to add EmailTemplateBundle
to your AppKernel.php
:
// app/AppKernel.php class AppKernel extends Kernel { //... public function registerBundles() { $bundles = array( //... new Fullpipe\ImageBundle\FullpipeImageBundle() ); return $bundles; } //... }
Configuration
fullpipe_email_template: # default from email from: # or simply from: noreply@example.com email: noreply@example.com name: noreply # default no reply email reply_to: # or simply reply_to: reply@example.com email: reply@example.com name: We are waiting for your reply # default utm-marks for links in emails (optional) utm: utm_source: source_test utm_medium: medium_test utm_campaign: campaign_test # default host for which utm-marks will be applied host: %router.request_context.scheme%://%router.request_context.host% # Your templates # requires at least one template templates: default: # template name # template uri template: "FullpipeEmailTemplateBundle:Template:default.html.twig" # custom utm-marks (optional) utm: utm_source: source_default utm_medium: medium_default utm_campaign: campaign_default # custorm host (optional) host: http://example.com # generate text version automatically, true by default generate_text_version: true #...
Usage
For example we need to send confirmation email, after user registration. First, we need to add template config:
fullpipe_email_template: #... templates: reg_confirmation: template: "AcmeWebBundle:EmailTemplates:reg_confirmation.html.twig" utm: utm_source: reg_confirmation utm_medium: email
Second, we need to create AcmeWebBundle:EmailTemplates:reg_confirmation.html.twig
:
{% block subject %}Good to you, {{ username }}{% endblock %} {% block body_html %} <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <style type="text/css"> ... </style> </head> <body> <h1>Hello, {{ username }}</h1> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Magnam deserunt magni libero quas aperiam, labore harum, eos expedita, dolores autem illum? Fugiat, molestias, minus. Libero impedit fugit inventore, aliquid perspiciatis.</p> </body> </html> {% endblock %}
And we could send our email:
$this->get('fullpipe_email_template.mailer') ->prepareMessage('reg_confirmation', array('username' => 'USERNAME!')) ->setTo('username@example.com', 'USERNAME!') ->send();
Profits
- if in twig template block
{% block body_text %}...{% endblock %}
is missing and optiongenerate_text_version
istrue
then text version will be generated by html2text - html version is processed by CssToInlineStyles