imag/notifier-bundle

Notifier bundle for Symfony 2

v1.0.1 2014-01-26 15:20 UTC

This package is auto-updated.

Last update: 2024-03-28 03:09:47 UTC


README

NotifierBundle implements the most essential and basic functionalities of Swift_Mailer. The best way, is to sent a Html mail with Twig templating engine. You can also add many attachments at the mail.

Contact

Nick: aways
IRC: irc.freenode.net - #sf-grenoble

Install

  1. Download with composer
  2. Enable
  3. Configure
  4. Use it

Download

Add NotifierBundle in your project's composer.json

{
    "require": {
        "imag/notifier-bundle": "1.0.*@stable"
    }
}

Enable

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new IMAG\NotifierBundle\IMAGNotifierBundle(),
    );
}

Configure

All next parameters are a default value.

#config.yml
imag_notifier:
    default_from: fqdn@d.tld
    default_subject: Defaul subject
    subject_prefix: "[Application][Tag] " #Default ''(empty string)

Use it

Html mail

$notifier = $this->get('imag_notifier.provider');

$html = $notifier->createHtmlMessage();

$attach = $notifier->createAttachment();
$attach
    ->loadFile('/tmp/toto')
    ->setFilename('toto.txt')
    ->setMimeType('application/txt')
    ;
$html->addAttachment($attach);

$attach = $notifier->createAttachment();
$attach->setData('Your content');
$html->addAttachment($attach);

$html
    ->addTo('foo@d.tld')
    ->addCc('foo@d.tld')
    ->setBcc(array(
        'foo@d1.tld',
    ))
    ->addBcc('foo@d2.tld')
    ->setSubject('Foo')
    ->setTemplate('IMAGYourBundle:Mail:contact.html.twig', array(
        'name' => 'toto',
        'subject' => 'subject',
        'date' => new \Datetime(),
        'body' => 'body',
    ))
    ;

$notifier->send($html);

Create basic mail

$notifier = $this->get('imag_notifier.provider');

$html = $notifier->createMessage();