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.
- Zend Framework 2 (latest master)
- Clone this project into your
./vendor/
directory.
-
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
-
Enabling it in your
application.config.php
file.<?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
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
type
andoptions
key can be specified - from - An array of arrays where each inner array should specify the
name
andemail
keys. Optionally andomain
key can be specified that is available in thedomains
option. If nodomain
is specified,default
is used. - layouts - An array of array where each inner array can specify a
plain
and/orhtml
key. The value for these keys should point to view file that you have defined in theview_manager
configuration. 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 thefrom
options array.layout
: a value that points to a key in thelayouts
array. If not specified, no layout is used.subject
: the subject of the email. If not specified thesubject
intemplate
will be used.template
: an array containing the keyshtml
,plain
andsubject
. These should point to a view script specified by theview_manager
.
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.