定制 enlitepro/enlite-mail 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

enlitepro/enlite-mail

Composer 安装命令:

composer require enlitepro/enlite-mail

包简介

The simple service for send mail with templates

README 文档

README

The simple module send mail with templates for ZF2.

Install

The recommended way to install is through composer.

{
    "require": {
        "enlitepro/enlite-mail": "~1.2.0"
    }
}

add EnliteMail to modules in config/application.config.php

Configure

The module use in default:

  • For transport Zend\Mail\Transport\Sendmail
  • For renderer - default renderer

For use other writes in service locator, add to config:

array(
    'enlite_mail' => array(
        'renderer' => 'YOUR_RENDERER_FOR_MAIL', // default ViewRenderer
        'transport' => 'YOUR_TRANSPORT_FOR_MAIL', // default MailTransport
        'from_mail' => 'YOUR_MAIL',
        'from_name' => 'YOUR_NAME',
    )
)

For example:

array(
    'enlite_mail' => array(
        'renderer' => 'ZfcTwigRenderer',
        'transport' => 'MailTransport',
    )
)

For change transport you may set a new transport in key "MailTransport" for service_manager. For example:

array(
    'service_manager' => array(
        'invokables' => array(
            'MailTransport' => 'Zend\Mail\Transport\Sendmail',
        ),
    )
);

Usage

use EnliteMail\Service;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorAwareTrait;

class MyService implements ServiceLocatorAwareInterface
{
    use ServiceLocatorAwareTrait,
        MailServiceTrait;

    public function test()
    {
        $mailService = $this->getMailService();

        // send any mail
        $message = $mailService->factoryMessage(); // this is Zend\Mail\Message
        // configure message
        // ...
        // send
        $mailService->sendMessage($message);

        // create mail from template and variables
        // variable will be pass to template
        $template = $mailService->createTemplate('my-module\controller\view', ['foo' => 'bar']);
        $mailService->sendTemplate($template, 'qwerty@example.com');
        // or, if you want operate message object before send
        $message = $mailService->createMessageFromTemplate($template);
        $mailService->sendMessage($message);
    }
}

Templates

Template system based on you renderer with all it benefits. There are only one new feature, headTitle plugin set message subject, not only page title.

example of layout/mail.twig

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    {% block title %}
        {% do headTitle('My Application').setSeparator(' - ') %}
    {% endblock %}
</head>
<body marginheight="0" topmargin="0" marginwidth="0" leftmargin="0" style="">
<div class="padded" style="padding:20px 20px 20px 20px">
    <table style="">
        <tr>
            <td style="">
{% block content %}{{ content|raw }}{% endblock content %}
            </td>
        </tr>
    </table>
</div>
</body>
</html>

example of application/mail/invite.twig

{% extends "layout/mail" %}

{% block content %}
    {% do headTitle("You're invited to MyApplication") %}
    
    Some variable: {{some_variable}}
{% endblock %}

统计信息

  • 总下载量: 904
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 4
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-08-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固