Zend Framework e-mail module. Using this library can easily create e-mail messages from PHTML templates (with optional layouts) and send them using configurable transports. Pluggable, EventManager-driven architecture allows you to customize every aspect of the process.

1.5.1 2017-11-15 18:11 UTC


Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version Total Downloads


MtMail handles common activities surrounding sending e-mail from applications, mainly creating messages from templates, and sending them through transport adapters.


  • factory for creating e-mail messages
  • factory for e-mail transport adapters, service for one-line dispatch
  • rendering templates from phtml files, using Zend\View and PhpRenderer
  • rendering templates with layouts
  • plugins for various common tasks: from setting default headers to generating plaintext version of HTML message
  • plugin support via dedicated plugin managers


Installation is supported via Composer:

$ composer require mtymek/mt-mail

Creating e-mails


By default MtMail doesn't require any extra configuration. It will use Zend\View to render templates accessible by your application.


Creating message from controller:

$mailService = $this->getServiceLocator()->get(\MtMail\Service\Mail::class);

$headers = [
    'to' => '',
    'from' => '',
$variables = [
    'userName' => 'John Doe',
$message = $mailService->compose($headers, 'application/mail/welcome.phtml', $variables);

This snippet will create a message, compose it with $headers and HTML body rendered from welcome.phtml template (injected with $variables array).


In order to give your e-mails common layout, you have to enable "Layout" plugin and tell it where to look for layout template:

return [
    'mt_mail' => [
        'composer_plugins' => [
        'layout' => 'application/mail/layout.phtml',

For more info about composing e-mail messages, check [the documentation](doc/Composing You can also check [documentation for plugins](doc/Composer

Sending e-mails


Update your application config:

return [
    'mt_mail' => [
        'transport' => \Zend\Mail\Transport\Smtp::class,
        'transport_options' => [
            'host' => '',
            'connection_class' => 'login',
            'connection_config' => [
                'username' => 'user',
                'password' => 'pass',
                'ssl' => 'tls',


Add following code to your controller:

// create and configure message
$message = new Message();
// ...

// send!
$mailService = $this->getServiceLocator()->get(\MtMail\Service\Mail::class);

For more info on sending e-mails, check [the documentation](doc/Sending