承接 hautzi/system-mail-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hautzi/system-mail-bundle

最新稳定版本:0.9.0

Composer 安装命令:

composer require hautzi/system-mail-bundle

包简介

This Bundle provides a nice abstraction for sending system emails

关键字:

README 文档

README

SensioLabsInsight Build Status Scrutinizer Code Quality

This bundle abstracts away sending system Messages. If instanciating a Swift_Message instance in your controllers seems fishy to you, this is probably what you are looking for.

This idea of this Bundle is to create some sort of XML configuration for each system mail to be sent (like "you have registered successfully, please activate your account" or "hey dude, you haven't been wasted your money on our platform for 10 days, please come back"), leveraging the power of twig.

Hey, why not looking in the code? It's kind of self-explanatory:

// AppBundle/Resources/emails/send-info.xml.twig
<?xml version="1.0"?>
<email xmlns="http://christoph-hautzinger.de/schema/system-mail-bundle"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://christoph-hautzinger.de/schema/system-mail-bundle http://christoph-hautzinger.de/schema/system-mail-bundle/email-1.0.xsd">
    <to name="{{ user.name }}">{{ user.email }}</to>
    <subject locale="de">Hallo {{ user.name }}</subject>
    <subject locale="en">Hello {{ user.name }}</subject>
    <messageHtml locale="en"><![CDATA[
        Hallo {{ user.name }}, 
        <a href="{{ url('') }}">please click this link</a>.
    ]]></messageHtml>
    <messageText locale="en" removeIndent="true">
        Hello {{ user.name }}, 
        please click this link: {{ url('') }}
    </messageText>
</email>

Then send out this mail explicitly by simply calling:

// from your code simply call
$container->get('system_mailer')->send('emails/send-info.xml.twig', [
    'user' => $user,
]);

Installation

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require hautzi/system-mail-bundle

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable the Bundle

Then, enable the bundle by adding the following line in the app/AppKernel.php file of your project:

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new Hautzi\SystemMailBundle\HautziSystemMailBundle(),
        );

        // ...
    }

    // ...
}

Configuration Options

Right now, you can provide default data

# in your app/config.yml
hautzi_system_mail:
    # defaults that are set for each mail, use blank 
    # if you don't want to set this
    defaults:
        subject:   ~
        replyTo:   ~
        from:
            email: ~
            name:  ~
        to:
            email: ~
            name:  ~
        cc:
            email: ~
            name:  ~
        bcc:
            email: ~
            name:  ~

Examples

$systemMailer = $container->get('system_mailer');

// sends out AppBundle/Resources/emails/registration/confirmUser.xml.twig
$systemMailer->send('emails/registration/confirmUser.xml.twig', ['user' => $user]);

// force locale of sent mail (when the recipient speaks another language than the user in the session)
$systemMailer->send('emails/info-mail.xml.twig', ['user' => $user], 'de');

// attach file to mail (or do something else with the Swift_Message instance)
$systemMailer->send('emails/message-with-pdf.xml.twig', [], null, function (\Swift_Message $message) {
     $message->attach(\Swift_Attachment::fromPath('my-document.pdf'))
});

License

This bundle is under the MIT license. See the complete license in the LICENSE file in the root dir of the bundle.

统计信息

  • 总下载量: 1.79k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 19
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 18
  • Watchers: 0
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-05-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固