ogogo/mailservice

该软件包最新版本(dev-master)没有提供许可证信息。

为 ZF2 提供可配置的邮件传输工厂(自定义)

dev-master 2015-01-30 18:50 UTC

This package is not auto-updated.

Last update: 2024-09-18 06:46:19 UTC


README

版本 1.0 由 Finbarr 创建

简介

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

需求

功能/目标

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

安装

主要设置

使用 composer

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

    "require": {
        "ogogo/mailservice": "dev-master"
    }
  2. 现在运行命令以下载 ZfcUser:

    $ php composer.phar update

安装后

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

    <?php
    return array(
        'modules' => array(
            // ...
            'MailService'
        ),
        // ...
    );
  2. 将本地和全局的配置文件从 ./vendor/ogogo/mailservice/config/mailservice.{local,global}.php.dist 复制到 ./config/autoload/mailservice.{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('mailservice_message');
$message = $mailService->createTextMessage($from, $to, $subject, $viewTemplate, $values);	
$mailService->send($message);

SMTP 设置

MailService 默认使用 sendmail,但您可以通过在配置文件中添加以下信息来设置使用 SMTP:

$settings = array(
    'transport_class' => '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
    )
);