This repository has been archived since we are not using it anymore internally. Feel free to use it AS-IS, we won't be providing any support anymore.
This package provides an easy-to-use mail-manager for ZF2 that lets you focus on creating your mails. Every e-mail is a class that you can configure based on your own needs. The mail manager uses a configurable mail adapter so that you don't have to worry about sending your mails.
curl -s https://getcomposer.org/installer | php
php composer.phar install
"phpro/zf-mail-manager": "~0.3"
<?php
return array(
'modules' => array(
'Phpro\MailManager',
// other libs...
),
// Other config
);
<?php
return array(
//
// Define a Default Mailmanager
//
'service_manager' => array(
'aliases' => array(
'Phpro\MailManager\DefaultAdapter' => 'Phpro\MailManager\Adapter\ZendMailAdapter',
)
),
//
// Paths to e-mail templates for renderable e-mail objects.
//
'view_manager' => [
'template_map' => [
'mails/layout' => __DIR__ . '/../view/mails/layout.phtml',
'mails/customer/registered' => __DIR__ . '/../view/mails/customer/registered.phtml',
],
],
//
// Custom e-mail plugin manager
//
'mail_manager' => [
'invokables' => [
'CustomerRegisteredMail' => 'CustomerRegisteredMail',
],
],
);
<?php
use MailManager\Mail\Base\ZendMail;
/**
* Class ShareCollection
*
* @package MailManager\Mail
*/
class CustomerRegisteredMail extends ZendMail
{
protected $viewFile = 'mails/customer/registered';
protected $subject = 'Customer Registered';
protected $to = ['[email protected]' => 'Me'];
protected $from = ['[email protected]' => 'Me'];
// Custom view parameters
protected $params = [
'name' => 'Me',
'email' => '[email protected]',
];
// Other settings like headers, attachments, ...
}
<?php
// Through the mail plugin manager:
$mailManager = $serviceManager->get('Phpro\MailManager');
$mail = $mailManager->get('CustomerRegisteredMail');
$mailManager->send($mail);
// Without the mail plugin manager:
$mailManager = $serviceManager->get('Phpro\MailManager');
$mail = new CustomerRegisteredMail();
$mailManager->send($mail);
At the moment following adapters are supported:
- ZendMail
- Mandrill