stijnkoopal / zf2-mail
Zend Framework 2 module that provides a highly configurable mail service
Installs: 355
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 3
Open Issues: 0
pkg:composer/stijnkoopal/zf2-mail
Requires
- php: >=5.3.0
Requires (Dev)
- phpunit/phpunit: 3.7.*
- zendframework/zendframework: 2.*
This package is not auto-updated.
Last update: 2025-12-16 08:56:22 UTC
README
Introduction
This module provides a highly configurable service for sending emails. It allows you to send emails with both plain as html content. Furthermore, it provides the ability to specify layouts for both content types.
Requirements
- Zend Framework 2 (latest master)
Installation
Main Setup
By cloning project (not recommended)
- Clone this project into your
./vendor/directory.
With composer
-
Add this project in your composer.json:
"require": { "stijnkoopal/zf2-mail": "dev-master" }
-
Now tell composer to download Zf2 mail by running the command:
$ php composer.phar update
Post installation
-
Enabling it in your
application.config.phpfile.<?php return array( 'modules' => array( // ... 'Mailing', ), // ... );
-
Copy config/mail.global.php.dist and config/mail.local.php.dist to your config directory
-
Remove the .dist extension from these files and fill in the blanks
Options
Thus module has some options to allow you to quickly customize the basic functionality.
The following options are available:
- domains - A array of key value pairs. The default key is used for email addresses that did not specify any domain
- transport - The specification for the email transport. A
typeandoptionskey can be specified - from - An array of arrays where each inner array should specify the
nameandemailkeys. Optionally andomainkey can be specified that is available in thedomainsoption. If nodomainis specified,defaultis used. - layouts - An array of array where each inner array can specify a
plainand/orhtmlkey. The value for these keys should point to view file that you have defined in theview_managerconfiguration. Hence, the view manager from the application is used to locate the view script. - mails - An array of arrays where each inner array can specify the following options:
from, a value that points to a key in thefromoptions array.layout: a value that points to a key in thelayoutsarray. If not specified, no layout is used.subject: the subject of the email. If not specified thesubjectintemplatewill be used.template: an array containing the keyshtml,plainandsubject. These should point to a view script specified by theview_manager.
Send email
Let $emailService be an instanceof Mailing\Service. (Can be obtained with the MailingServiceProviderTrait). An
email is then send with $email->sendMail($message, 'alias', $variables). The $message variable is an instance of
Zend\Mail\Message and you should specify addresses in this object. The second parameter is a key in the mails array
specified in the configuration. Variables can be passed as last parameter. These will be available in your view script.