janmalte / jm-mail-service
此包已被废弃且不再维护。未建议替代包。
ZF2邮件服务模块,简化ZendMail的使用
0.1.1
2014-04-28 16:11 UTC
Requires
- php: >=5.3.3
- zendframework/zendframework: 2.2.*
This package is not auto-updated.
Last update: 2020-10-16 19:34:46 UTC
README
由Malte Gerth创建
简介
邮件服务,简化ZF2邮件组件的使用。支持添加附件和发送HTML消息。可以在发送前使用Zend Mail组件修改消息。
要求
- Zend Framework 2 (2.2.*)
特性
- 使用视图辅助器作为消息模板的Zend View Scripts
- 无需修改即可使用Zend Mail组件
- 简化发送多部分消息的处理
- 通过调用单个方法轻松添加附件
- 使用本地Zend Mail传输类
安装
-
在您的composer.json中添加此项目和JmMailService
"require": { "janmalte/jm-mail-service": "dev-master" }
-
现在运行以下命令来告诉composer下载JmMailService
$ php composer.phar update
-
在您的
application.config.php
文件中启用模块。<?php return array( 'modules' => array( // ... 'JanMalte\JmMailService', ), // ... );
选项
JmMailService模块提供了一些选项,允许您自定义功能。安装JmMailService后,在./config/autoload/
中创建一个新的配置文件或更改现有的配置文件以设置所需的值。
以下选项位于配置键jm-mail-service
下
- mail_transport_key - 要使用的传输服务的服务管理器键。
- mail_service - 邮件服务的选项。请参阅下一节。
邮件服务选项
以下选项位于JmMailService选项的配置键mail_service
下
- default_from - 作为邮件服务发送者的默认邮件地址。
- default_from_name - 作为邮件服务发送者的默认名称。
用法
邮件服务已在服务管理器中注册,可以通过调用get('JanMalte\JmMailService\Service\Mail')
从中检索。
```php
// Get the mail service
$mailService = $serviceLocator->get('JanMalte\JmMailService\Service\Mail');
```
发送邮件消息只需几个命令。
```php
// Reset the mail service
$mailService->reset();
// Set the mail template
$mailService->setTemplate($templateFile);
// Parse the template
$mailService->parseTemplate($templateValues);
// Add a recipient for the message
$mailMessage = $mailService->getMailMessage();
$mailMessage->setTo($recipientEmail, $recipientName);
// Send the mail message
$mailService->send();
```
提供方法链,因此您可以缩短命令为以下内容
```php
// Use the mail service with method chaining
$mailService->reset()
->setTemplate($templateFile)
->parseTemplate($templateValues);
// Add a recipient for the message
$$mailService->getMailMessage()
->setTo($recipientEmail, $recipientName);
// Send the mail message
$mailService->send();
```
模板文件必须与其它视图脚本位于同一路径下。通常这将是<vendor>/<module>/view/