ripaclub/zf2-mailman
最新稳定版本:v0.3.2
Composer 安装命令:
composer require ripaclub/zf2-mailman
包简介
ZF2 module to manage email delivery
关键字:
README 文档
README
What is this?
This is a ZF2 Module that gives you a simple way to configure one or multiple mail services.
It supports all transports shipped with ZF2, e.g. any transport that implements the Zend\Mail\Transport\TransportInterface.
It also has a transport for Mandrill. If you wish to use it install also mandrill/mandrill (versions 1.0.*) library.
Installation
Add ripaclub/zf2-mailman to your composer.json.
{
"require": {
"ripaclub/zf2-mailman": "~0.3.2"
}
}
Usage
Configure a transport in your configuration file.
'mailman' => [ 'MailMan\Gmail' => [ 'default_sender' => 'my-name-is-methos@gmail.com', 'transport' => [ 'type' => 'smtp', 'options' => [ 'host' => 'smtp.gmail.com', 'port' => '587', 'connection_class' => 'login', 'connection_config' => [ 'ssl' => 'tls', 'username' => 'my-name-is-methos@gmail.com', 'password' => 'MYSECRETPASSWORD', ] ] ], ], ],
Do not forget to add MailMan module to you application.config.php file.
'modules' => [ // ... 'MailMan', 'Application', ],
Text only message
Then we send a text only message.
$message = new \MailMan\Message(); $message->addTextPart('Test email'); $message->setSubject('My name is methos'); $message->addFrom('my-name-is-methos@gmail.com', 'Methos'); $message->addTo('ripaclub@gmail.com', 'RipaClub'); /** @var \MailMan\Service\MailService $mailService */ $mailService = $this->getServiceLocator()->get('MailMan\Gmail'); $mailService->send($message);
Message with attachment
Do you want to send an email message with an attachment from filesystem?
$message = new \MailMan\Message(); $message->addAttachment('/path/to/an/attachment.png'); $message->setBody('Test email'); $message->setSubject('My name is methos'); $message->addFrom('my-name-is-methos@gmail.com', 'Methos'); $message->addTo('ripaclub@gmail.com', 'RipaClub'); /** @var \MailMan\Service\MailService $mailService */ $mailService = $this->getServiceLocator()->get('MailMan\Gmail'); $mailService->send($message);
Message using a template
$content = new ViewModel(); $content->setTemplate('email/example.phtml'); $content->setVariable('name', 'RipaClub'); $message = new \MailMan\Message(); $message->setSubject('Example email'); $message->addHtmlPart($this->getServiceLocator()->get('ViewRenderer')->render($content)); $message->addTo('ripaclub@gmail.com', 'RipaClub'); /** @var $mailService \MailMan\Service\MailService */ $mailService = $this->getServiceLocator()->get('MailMan\Gmail'); $mailService->send($message);
The content of email/example.phtml file will be:
<h2>Hi <?= $name; ?>,</h2> This is an example email with template.
Transports configuration examples
Mandrill
To use the Mandrill transport add "mandrill/mandrill" to your composer.json.
Then configure it.
'mailman' => [ 'MailMan\Mandrill' => [ 'default_sender' => 'test@mail.com', 'transport' => [ 'type' => 'mandrill', 'options' => [ 'api_key' => 'MYSECRETMANDRILLKEY', 'sub_account' => 'my-optional-subaccount-if-any' ], ], ], ]
SMTP
In this example we use the SMTP transport (shipped by ZF2).
'mailman' => [ 'MailMan\SMTP' => [ 'default_sender' => 'my-name-is-methos@gmail.com', 'transport' => [ 'type' => 'smtp', 'options' => [ 'host' => 'smtp.gmail.com', 'port' => '587', 'connection_class' => 'login', 'connection_config' => [ 'ssl' => 'tls', 'username' => 'my-name-is-methos@gmail.com', 'password' => 'MYSECRETPASSWORD', ] ] ], ], ],
Sendmail
In this example we use the Sendmail transport (shipped by ZF2).
'mailman' => [ 'MailMan\Sendmail' => [ 'default_sender' => 'my-name-is-methos@yourdomain.com', 'transport' => [ 'type' => 'sendmail' ], ], ],
统计信息
- 总下载量: 371
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 3
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: BSD-2-Clause
- 更新时间: 2014-10-30