2017 © Pedro Peláez
 

library zf2-mailman

ZF2 module to manage email delivery

image

ripaclub/zf2-mailman

ZF2 module to manage email delivery

  • Thursday, April 28, 2016
  • by leodido
  • Repository
  • 3 Watchers
  • 7 Stars
  • 345 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 2 Open issues
  • 8 Versions
  • 5 % Grown

The README.md

ZF2 Mail Manager

Packagist Travis branch Coveralls branch, (*1)

What is this?

This is a ZF2 Module that gives you a simple way to configure one or multiple mail services., (*2)

It supports all transports shipped with ZF2, e.g. any transport that implements the Zend\Mail\Transport\TransportInterface., (*3)

It also has a transport for Mandrill. If you wish to use it install also mandrill/mandrill (versions 1.0.*) library., (*4)

Installation

Add ripaclub/zf2-mailman to your composer.json., (*5)

{
   "require": {
       "ripaclub/zf2-mailman": "~0.3.2"
   }
}

Usage

Configure a transport in your configuration file., (*6)

'mailman' => [
    'MailMan\Gmail' => [
        'default_sender' => 'my-name-is-methos@gmail.com',
        'transport' => [
            'type' => 'smtp',
            'options' => [
                 'host' => 'smtp.gmail.com',
                 'port' => '587',
                 'connection_class' => 'login',
                 'connection_config' => [
                     'ssl' => 'tls',
                     'username' => 'my-name-is-methos@gmail.com',
                     'password' => 'MYSECRETPASSWORD',
                 ]
             ]
        ],
    ],
],

Do not forget to add MailMan module to you application.config.php file., (*7)

'modules' => [
        // ...
        'MailMan',
        'Application',
],

Text only message, (*8)

Then we send a text only message., (*9)

$message = new \MailMan\Message();
$message->addTextPart('Test email');
$message->setSubject('My name is methos');
$message->addFrom('my-name-is-methos@gmail.com', 'Methos');
$message->addTo('ripaclub@gmail.com', 'RipaClub');
/** @var \MailMan\Service\MailService $mailService */
$mailService = $this->getServiceLocator()->get('MailMan\Gmail');
$mailService->send($message);

Message with attachment, (*10)

Do you want to send an email message with an attachment from filesystem?, (*11)

$message = new \MailMan\Message();
$message->addAttachment('/path/to/an/attachment.png');
$message->setBody('Test email');
$message->setSubject('My name is methos');
$message->addFrom('my-name-is-methos@gmail.com', 'Methos');
$message->addTo('ripaclub@gmail.com', 'RipaClub');
/** @var \MailMan\Service\MailService $mailService */
$mailService = $this->getServiceLocator()->get('MailMan\Gmail');
$mailService->send($message);

Message using a template, (*12)

$content = new ViewModel();
$content->setTemplate('email/example.phtml');
$content->setVariable('name', 'RipaClub');
$message = new \MailMan\Message();
$message->setSubject('Example email');
$message->addHtmlPart($this->getServiceLocator()->get('ViewRenderer')->render($content));
$message->addTo('ripaclub@gmail.com', 'RipaClub');
/** @var $mailService \MailMan\Service\MailService */
$mailService = $this->getServiceLocator()->get('MailMan\Gmail');
$mailService->send($message);

The content of email/example.phtml file will be:, (*13)

<h2>Hi <?= $name; ?>,</h2>
This is an example email with template.

Transports configuration examples

Mandrill

To use the Mandrill transport add "mandrill/mandrill" to your composer.json., (*14)

Then configure it., (*15)

'mailman' => [
    'MailMan\Mandrill' => [
        'default_sender' => 'test@mail.com',
        'transport' => [
            'type' => 'mandrill',
            'options' => [
                'api_key' => 'MYSECRETMANDRILLKEY',
                'sub_account' => 'my-optional-subaccount-if-any'
            ],
        ],
    ],
]

SMTP

In this example we use the SMTP transport (shipped by ZF2)., (*16)

'mailman' => [
    'MailMan\SMTP' => [
        'default_sender' => 'my-name-is-methos@gmail.com',
        'transport' => [
            'type' => 'smtp',
            'options' => [
                 'host' => 'smtp.gmail.com',
                 'port' => '587',
                 'connection_class' => 'login',
                 'connection_config' => [
                     'ssl' => 'tls',
                     'username' => 'my-name-is-methos@gmail.com',
                     'password' => 'MYSECRETPASSWORD',
                 ]
             ]
        ],
    ],
],

Sendmail

In this example we use the Sendmail transport (shipped by ZF2)., (*17)

'mailman' => [
    'MailMan\Sendmail' => [
        'default_sender' => 'my-name-is-methos@yourdomain.com',
        'transport' => [
            'type' => 'sendmail'
        ],
    ],
],

Analytics, (*18)

The Versions

28/04 2016

dev-develop

dev-develop

ZF2 module to manage email delivery

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

mail file email zend framework messages mandrill message zf memory smtp sendmail mail manager

18/03 2016

dev-master

9999999-dev

ZF2 module to manage email delivery

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

mail file email zend framework messages mandrill message zf memory smtp sendmail mail manager

18/03 2016

v0.3.2

0.3.2.0

ZF2 module to manage email delivery

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

mail file email zend framework messages mandrill message zf memory smtp sendmail mail manager

10/06 2015

v0.3.0

0.3.0.0

ZF2 module to manage email delivery

  Sources   Download

BSD-2-Clause

The Requires

 

The Development Requires

mail file email zend framework messages mandrill message zf memory smtp sendmail mail manager