mtymek / mt-mail
Zend Framework 电子邮件模块。使用此库可以轻松地从 PHTML 模板(可选布局)创建电子邮件消息,并使用可配置的传输方式发送它们。可插拔、由 EventManager 驱动的架构允许您自定义过程的各个方面。
1.5.1
2017-11-15 18:11 UTC
Requires
- php: ^5.5 || ^7.0
- zendframework/zend-escaper: ^2.2.1
- zendframework/zend-eventmanager: ^2.6.0 || ^3.0.1
- zendframework/zend-filter: ^2.2.1
- zendframework/zend-mail: ^2.2.1
- zendframework/zend-modulemanager: ^2.2.1
- zendframework/zend-servicemanager: ^2.7.5 || ^3.0.3
- zendframework/zend-validator: ^2.2.1
- zendframework/zend-view: ^2.2.1
Requires (Dev)
- malukenho/docheader: ^0.1.6
- phpunit/phpunit: ^5.7
- squizlabs/php_codesniffer: ^2.3
- zendframework/zend-console: ^2.2.1
- zendframework/zend-http: ^2.2.1
- zendframework/zend-i18n: ^2.2.1
- zendframework/zend-log: ^2.2.1
- zendframework/zend-mvc: ^2.2.1
- zendframework/zend-serializer: ^2.2.1
This package is auto-updated.
Last update: 2024-09-05 03:49:32 UTC
README
简介
MtMail 处理与应用程序发送电子邮件相关的常见活动,主要是从模板创建消息,并通过传输适配器发送它们。
功能
- 创建电子邮件消息的工厂
- 电子邮件传输适配器工厂,用于单行发送的服务
- 从
phtml
文件渲染模板,使用Zend\View
和PhpRenderer
- 带有布局的模板渲染
- 用于各种常见任务的插件:从设置默认头信息到生成 HTML 消息的纯文本版本
- 通过专门的插件管理器支持插件
安装
安装通过 Composer 支持
$ composer require mtymek/mt-mail
创建电子邮件
配置
默认情况下,MtMail 不需要任何额外配置。它将使用 Zend\View
来渲染应用程序可访问的模板。
用法
从控制器创建消息
$mailService = $this->getServiceLocator()->get(\MtMail\Service\Mail::class); $headers = [ 'to' => 'johndoe@domain.com', 'from' => 'contact@mywebsite.com', ]; $variables = [ 'userName' => 'John Doe', ]; $message = $mailService->compose($headers, 'application/mail/welcome.phtml', $variables);
此代码段将创建一个消息,使用 $headers
和从 welcome.phtml
模板(注入 $variables
数组)渲染的 HTML 正文来编写。
布局
为了使您的电子邮件具有共同的布局,您必须启用“布局”插件,并告诉它在哪里查找布局模板
return [ 'mt_mail' => [ 'composer_plugins' => [ 'Layout', ], 'layout' => 'application/mail/layout.phtml', ], ];
有关编写电子邮件消息的更多信息,请参阅 [文档](doc/Composing messages.md)。您还可以查看 [插件文档](doc/Composer Plugins.md)。
发送电子邮件
配置
更新应用程序配置
return [ 'mt_mail' => [ 'transport' => \Zend\Mail\Transport\Smtp::class, 'transport_options' => [ 'host' => 'some-host.com', 'connection_class' => 'login', 'connection_config' => [ 'username' => 'user', 'password' => 'pass', 'ssl' => 'tls', ], ], ], ];
用法
将以下代码添加到您的控制器中
// create and configure message $message = new Message(); $message->addTo('johndoe@domain.com'); // ... // send! $mailService = $this->getServiceLocator()->get(\MtMail\Service\Mail::class); $mailService->send($message);
有关发送电子邮件的更多信息,请参阅 [文档](doc/Sending messages.md)。