Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
This bundle helps you to deal with emails in your Symfony2 app. Render emails from Twig or Database, it's easy!.
branch: master

Email Templates Bundle for Symfony2

This bundle can be useful when you need to send diffrent kind of emails from your app, for eg. user registration or forgot password email. Read usage section.

Build Status


Add bundle via composer (Symfony 2.1)

php composer.phar require sfk/email-template-bundle:dev-master

Add bundle to your application kernel

// app/AppKernel.php
public function registerBundles() 
    $bundles = array(
        // ...
        new Sfk\EmailTemplateBundle\SfkEmailTemplateBundle(),


  • Create registration email template in your bundle
  • Edit template
// src/Acme/DemoBundle/Resources/views/[Emails]/user_registered.html.twig
{% extends 'SfkEmailTemplateBundle::email.html.twig' %}

{% block from -%}
{%- endblock %}

{% block subject -%}
Thanks for registering {{ first_name }}!
{%- endblock %}

{% block body -%}
Hello {{ first_name }},
<br />
<br />
Thank you for registering at our website! below your account details:
<br />
<br />
First Name: {{ first_name }}<br />
Last Name: {{ last_name }}<br />
Email: {{ email }}<br />
<br />
{%- endblock %}
  • Now you can send it from your controller
// ...
class UserController extends Controller {
    public function registerAction() {
        // ...
        if ($form->isValid()) {
            //.. some actions here
            $formData = array(
                'email' => '',
                'first_name' => 'John',
                'last_name' => 'Doe',
            $template = $this->get('sfk_email_template.loader')
                ->load('AcmeDemoBundle:Emails:user_registered.html.twig', $formData)
            $message = \Swift_Message::newInstance()
                ->setBody($template->getBody(), 'text/html')
            // send email

Thats's it! John Doe will receive an email as below:

Hello John,
Thank you for registering at our website! below your account details:

First Name: John
Last Name: Doe


Advanced Usage


This bundle was inspired by Rendering emails with Twig in Symfony2 post. Many thanks to its author.

Something went wrong with that request. Please try again.