finbarrmccarthy/finbarr-mailservice

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

为ZF2(FMC Custom)提供可配置的邮件传输工厂

dev-master 2014-05-16 13:03 UTC

This package is not auto-updated.

Last update: 2024-09-24 07:32:20 UTC


README

版本 0.0.2 由 Finbarr 创建

简介

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

要求

功能/目标

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

安装

主要设置

使用composer

  1. 在您的composer.json中添加此项目和需求

    "require": {
        "finbarrmccarthy/finbarr-mailservice": "1.*"
    }
  2. 现在运行以下命令告诉composer下载FinbarrMailService:

    $ php composer.phar update

安装后

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

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

SMTP设置

FinbarrMailService默认使用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
    )
);