imag/notifier-bundle

Symfony 2 的 Notifier bundle

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

This package is auto-updated.

Last update: 2024-08-28 04:14:22 UTC


README

NotifierBundle 实现了 Swift_Mailer 的最基本和最重要的功能。最佳做法是使用 Swift_Mailer 发送 HTML 邮件,并使用 Twig 模板引擎。您还可以在邮件中添加多个附件。

联系方式

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

安装

  1. 使用 composer 下载
  2. 启用
  3. 配置
  4. 使用它

下载

在项目的 composer.json 中添加 NotifierBundle

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

启用

<?php
// app/AppKernel.php

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

配置

所有后续参数都是默认值。

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

使用它

HTML 邮件

$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);

创建基本邮件

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

$html = $notifier->createMessage();