mtymek / mt-mail
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.
Installs: 37 065
Dependents: 3
Suggesters: 0
Security: 0
Stars: 18
Watchers: 6
Forks: 14
Open Issues: 4
Requires
- php: ^5.5 || ^7.0
- zendframework/zend-escaper: ^2.2.1
- zendframework/zend-eventmanager: ^2.6.0 || ^3.0.1
- zendframework/zend-filter: ^2.2.1
- zendframework/zend-mail: ^2.2.1
- zendframework/zend-modulemanager: ^2.2.1
- zendframework/zend-servicemanager: ^2.7.5 || ^3.0.3
- zendframework/zend-validator: ^2.2.1
- zendframework/zend-view: ^2.2.1
Requires (Dev)
- malukenho/docheader: ^0.1.6
- phpunit/phpunit: ^5.7
- squizlabs/php_codesniffer: ^2.3
- zendframework/zend-console: ^2.2.1
- zendframework/zend-http: ^2.2.1
- zendframework/zend-i18n: ^2.2.1
- zendframework/zend-log: ^2.2.1
- zendframework/zend-mvc: ^2.2.1
- zendframework/zend-serializer: ^2.2.1
This package is auto-updated.
Last update: 2024-11-05 04:08:04 UTC
README
Introduction
MtMail handles common activities surrounding sending e-mail from applications, mainly creating messages from templates, and sending them through transport adapters.
Features:
- factory for creating e-mail messages
- factory for e-mail transport adapters, service for one-line dispatch
- rendering templates from
phtml
files, usingZend\View
andPhpRenderer
- 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
Installation is supported via Composer:
$ composer require mtymek/mt-mail
Creating e-mails
Configuration
By default MtMail doesn't require any extra configuration. It will use Zend\View
to render
templates accessible by your application.
Usage
Creating message from controller:
$mailService = $this->getServiceLocator()->get(\MtMail\Service\Mail::class); $headers = [ 'to' => 'johndoe@domain.com', 'from' => 'contact@mywebsite.com', ]; $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).
Layouts
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', ], 'layout' => 'application/mail/layout.phtml', ], ];
For more info about composing e-mail messages, check [the documentation](doc/Composing messages.md). You can also check [documentation for plugins](doc/Composer Plugins.md).
Sending e-mails
Configuration
Update your application config:
return [ 'mt_mail' => [ 'transport' => \Zend\Mail\Transport\Smtp::class, 'transport_options' => [ 'host' => 'some-host.com', 'connection_class' => 'login', 'connection_config' => [ 'username' => 'user', 'password' => 'pass', 'ssl' => 'tls', ], ], ], ];
Usage
Add following code to your controller:
// create and configure message $message = new Message(); $message->addTo('johndoe@domain.com'); // ... // send! $mailService = $this->getServiceLocator()->get(\MtMail\Service\Mail::class); $mailService->send($message);
For more info on sending e-mails, check [the documentation](doc/Sending messages.md).