2017 © Pedro Peláez
 

symfony-bundle email-template-bundle

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

image

adesigns/email-template-bundle

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

  • Friday, August 29, 2014
  • by mikeyudin
  • Repository
  • 1 Watchers
  • 0 Stars
  • 347 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 10 Forks
  • 0 Open issues
  • 6 Versions
  • 4 % Grown

The README.md

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., (*1)

Build Status, (*2)

Installation

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(),
    );
}

Usage

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

{% block from -%}
example@example.org
{%- 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 />
Thanks
{%- endblock %}
  • Now you can send it from your controller
<?php
// ...
class UserController extends Controller {
    public function registerAction() {
        // ...
        if ($form->isValid()) {
            //.. some actions here
            $formData = array(
                'email' => 'johndoe@example.com',
                '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()
                ->setSubject($template->getSubject())
                ->setFrom($template->getFrom())
                ->setBody($template->getBody(), 'text/html')
                ->setTo($formData['email'])
            ;
            // send email
            $this->get('mailer')->send($message);
        }
    }
}

Thats's it! John Doe will receive an email as below:, (*3)

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

First Name: John
Last Name: Doe
Email: johndoe@example.com

Thanks

Advanced Usage

Credits

This bundle was inspired by Rendering emails with Twig in Symfony2 post. Many thanks to its author., (*4)

The Versions

29/08 2014

dev-master

9999999-dev http://github.com/adesigns/EmailTemplateBundle

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

  Sources   Download

MIT

The Requires

 

by Oleg Khussainov

twig email doctrine email emails integration

16/04 2014

dev-release/v1.0.1

dev-release/v1.0.1 http://github.com/getme/EmailTemplateBundle

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

  Sources   Download

MIT

The Requires

 

by Oleg Khussainov

twig email doctrine email emails integration

16/04 2014

v1.0.1

1.0.1.0 http://github.com/getme/EmailTemplateBundle

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

  Sources   Download

MIT

The Requires

 

by Oleg Khussainov

twig email doctrine email emails integration

04/12 2012

v1.0.0

1.0.0.0 http://github.com/getme/EmailTemplateBundle

This bundle helps you to deal with emails in your app. Render emails from Twig or Database, it's easy!.

  Sources   Download

MIT

The Requires

 

by Oleg Khussainov

twig email doctrine email emails integration

01/11 2012

v0.9.0

0.9.0.0 http://github.com/getme/EmailTemplateBundle

This bundle helps you to deal with emails in your app. Render emails from Twig or Database, it's easy!.

  Sources   Download

MIT

The Requires

 

by Oleg Khussainov

twig email doctrine email emails integration

23/10 2012

dev-doctrine_loader

dev-doctrine_loader http://github.com/getme/EmailTemplateBundle

This bundle provides an easy way to store and send diffrent kind of emails from your app

  Sources   Download

MIT

The Requires

 

by Oleg Khussainov

twig email doctrine email emails integration