joacub / goalio-mailservice
为 ZF2 提供可配置的邮件传输工厂
1.2.1
2014-10-27 14:19 UTC
Requires
- php: >=5.3.3
- zendframework/zendframework: 2.3.*
This package is not auto-updated.
Last update: 2024-09-20 02:37:37 UTC
README
版本 1.2.0 由 goalio UG (haftungsbeschränkt) 创建
简介
为 ZF2 提供可配置的邮件传输工厂和简单的消息传递
需求
- Zend Framework 2 (> 2.3.3).
特性 / 目标
- 配置传输服务以使用 Zend\Mail [已完成]
变更日志
随着 ZF2.3 的发布,传输工厂发生了变化。这导致 goaliomailservice.global.php(和 goaliomailservice.local.php)中的配置发生了变化。我在自己的工厂中尝试了这一点,但请注意这一点。
安装
主要设置
使用 composer
-
将此项目和需求添加到您的 composer.json 文件中
"require": { "goalio/goalio-mailservice": "1.*" }
-
现在运行以下命令来让 composer 下载 GoalioMailService
$ php composer.phar update
安装后
-
在您的
application.config.php
文件中启用它。<?php return array( 'modules' => array( // ... 'GoalioMailService' ), // ... );
-
将本地和全局的配置文件从
./vendor/goalio/goalio-mailservice/config/goaliomailservice.{local,global}.php.dist
复制到./config/autoload/goaliomailservice.{local,global}.php
并根据需要更改值。 -
如果您正在使用 FileTransport(用于开发),请创建
./data/mail
目录。
使用
// The template used by the PhpRenderer to create the content of the mail
$viewTemplate = 'module/email/testmail';
// The ViewModel variables to pass into the renderer
$value = array('foo' => 'bar');
$mailService = $this->getServiceManager()->get('goaliomailservice_message');
$message = $mailService->createTextMessage($from, $to, $subject, $viewTemplate, $values);
$mailService->send($message);
SMTP 设置
GoalioMailService 默认使用 sendmail,但您可以通过在配置文件中输入相关信息来将其配置为使用 SMTP,如下所示
$settings = array(
'type' => 'Zend\Mail\Transport\Smtp',
'options_class' => 'Zend\Mail\Transport\SmtpOptions',
'options' => array(
'host' => 'smtp.gmail.com',
'connection_class' => 'login',
'connection_config' => array(
'ssl' => 'tls',
'username' => 'YOUR-USERNAME-HERE@gmail.com',
'password' => 'YOUR-PASSWORD-HERE'
),
'port' => 587
)
);