samdeb / easymailbundle
easyMailBundle是针对Symfony2的,它提供了一个方便的方式发送带模板的电子邮件。
v1.0
2017-05-25 18:55 UTC
Requires
- php: >=5.3.2
This package is not auto-updated.
Last update: 2024-09-23 06:23:09 UTC
README
easyMailBundle是针对Symfony2的,它提供了一个方便的方式发送带模板的电子邮件。
安装
easyMailBundle使用Composer,请访问Composer网站获取更多信息。
以下简单命令将安装easyMailBundle
到您的项目中。它还会在您的composer.json
中添加一个新条目,并更新composer.lock
。
composer require samdeb/easymailbundle:dev-master
一旦新项目设置完成,打开composer.json文件,并将samdeb/easymailbundle添加为依赖项
//composer.json //... "require": { //other bundles "samdeb/easymailbundle": "dev-master"
保存文件,并使用命令行更新项目
composer update
现在只需更新app/AppKernel.php
//app/AppKernel.php //... public function registerBundles() { $bundles = array( //Other bundles new ABC\EasyMailBundle\ABCEasyMailBundle(), );
配置示例
将bundle添加到orm配置:您可以配置默认查询参数名称和模板
#app/config/config.yml
#...
abc_easy_mail:
from: system@mydomain.com
reply: soporte@mydomain.com
default_theme : ~
或者
#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
现在您就完成了。
使用示例
控制器(基础)
// 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'); } }
控制器(高级)
// 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'); } }
视图
{% extends "ABCEasyMailBundle:Default:Layout.html.twig" %} {% block logo %} {{logo}} {% endblock %} {% block title %} {{title}} {% endblock %} {% block content %} {{content}} {% endblock %} {% block footer %} {{footer}} {% endblock %}