goalio/goalio-mailservice

为 ZF2 提供可配置的邮件传输工厂

1.2.1 2014-10-27 14:19 UTC

This package is not auto-updated.

Last update: 2024-09-14 12:29:17 UTC


README

版本 1.2.0 由 goalio UG (haftungsbeschränkt) 创建

简介

为 ZF2 提供可配置的邮件传输工厂和简单消息功能

要求

特性/目标

  • 配置传输服务以使用 Zend\Mail [已完成]

变更日志

从 ZF2.3 开始,传输工厂发生了变化。这需要在 goaliomailservice.global.php(以及 goaliomailservice.local.php)中的配置进行修改。我尝试在我的工厂中检查这些变化,但请注意这一点。

安装

主要设置

使用 composer

  1. 将此项目和需求添加到您的 composer.json 文件中

    "require": {
        "goalio/goalio-mailservice": "1.*"
    }
  2. 现在运行以下命令以让 composer 下载 GoalioMailService:

    $ php composer.phar update

安装后

  1. 在您的 application.config.php 文件中启用它。

    <?php
    return array(
        'modules' => array(
            // ...
            'GoalioMailService'
        ),
        // ...
    );
  2. 将本地和全局的配置文件从 ./vendor/goalio/goalio-mailservice/config/goaliomailservice.{local,global}.php.dist 复制到 ./config/autoload/goaliomailservice.{local,global}.php,并根据需要更改值。

  3. 如果您使用的是 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
    )
);