finbarrmccarthy/mailservice

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

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

dev-master 2014-05-16 16:31 UTC

This package is not auto-updated.

Last update: 2024-09-28 15:08:26 UTC


README

版本 0.0.2 由 Finbarr 创建

介绍

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

要求

功能/目标

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

安装

主要设置

使用composer

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

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

    $ php composer.phar update

安装后

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

    <?php
    return array(
        'modules' => array(
            // ...
            'MailService'
        ),
        // ...
    );
  2. 将本地和全局配置文件从./vendor/finbarrmccarthy/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
    )
);