samdeb/easymailbundle

The easyMailBundle, for Symfony2, provide an easy way to send email with temple

v1.0 2017-05-25 18:55 UTC

This package is not auto-updated.

Last update: 2024-03-25 03:56:59 UTC


README

The easyMailBundle, for Symfony2, provide an easy way to send email with temple

Installing

easyMailBundle uses Composeris, please checkout the composer website for more information.

The simple following command will install easyMailBundle into your project. It also add a new entry in your composer.json and update the composer.lock as well.

composer require samdeb/easymailbundle:dev-master

Once the new project is set up, open the composer.json file and add the samdeb/easymailbundle as a dependency:

//composer.json
//...
"require": {
        //other bundles
        "samdeb/easymailbundle": "dev-master"

Save the file and have composer update the project via the command line:

composer update

Now just update the app/AppKernel.php:

//app/AppKernel.php
//...
    public function registerBundles()
    {
        $bundles = array(
            //Other bundles
            new ABC\EasyMailBundle\ABCEasyMailBundle(),
        );

Configuration example

Add the bundle to orm configuration: You can configure default query parameter names and templates

#app/config/config.yml
#...
abc_easy_mail:
    from: system@mydomain.com
    reply: soporte@mydomain.com
    default_theme : ~ 

or

#app/config/config.yml
#...
abc_easy_mail:
    from: system@mydomain.com
    reply: soporte@mydomain.com
    default_theme : mytheme
    themes:
        mytheme: 
            twig: ABCEasyMailBundle:Default:easyMail.html.twig
            logo: 'https://github.com/samrodriguez/easyMailBundle/blob/master/web/img/logo.png'
            title: 'Company Name'
            footer: 'Atte.'
        othertheme: 
            twig: MyBundle:Default:mail.html.twig
            

and now you're done.

Usage examples:

Controller (Basic)

// ABC\EasyMailBundle\Controller\DefaultController.php

class DefaultController extends Controller
{
    public function indexAction()
    {
        $mail = $this->get('easy.mailer');
        $settings = array(
                          'to'=>'email@mydomain.com',
                          'subject' => 'This is my subject',
                          'body'    => array(
                                        'content' => 'Put your text',
                                    )
                    );
        $mail->send($settings);
        return $this->render('ABCEasyMailBundle:Default:index.html.twig');
    }
}

Controller (Advanced)

// ABC\EasyMailBundle\Controller\DefaultController.php

class DefaultController extends Controller
{
    public function indexAction()
    {
        $mail = $this->get('easy.mailer');
        $settings = array('default_theme'=>'other',
                          'to'=>'email@mydomain.com',
                          /*
                          'cc'=>'myemail@mydomain.com',
                          'bcc'=> 'otheremail@mydomain.com',
                          */
                          'subject' => 'This is my subject',
                          'body'    => array(
                                        /*
                                         'logo'   => 'Mylogo.jpg',
                                         'title'  => 'Diferent Company Name',
                                         */
                                        'content' => 'Put your text',
                                        'footer'  => 'Saludos'
                                    )
                    );
        $mail->send($settings);
        return $this->render('ABCEasyMailBundle:Default:index.html.twig');
    }
}

View

{% extends "ABCEasyMailBundle:Default:Layout.html.twig" %}

{% block logo %} {{logo}} {% endblock %}
{% block title %} {{title}} {% endblock %}
{% block content %} {{content}} {% endblock %}
{% block footer %} {{footer}} {% endblock %}