netglue/ng-mtmail

This package is abandoned and no longer maintained. No replacement package was suggested.

ZF2 Module providing a multipart template driven email message creation service using the ZF view layer

0.1 2013-04-08 13:01 UTC

This package is not auto-updated.

Last update: 2020-03-30 12:47:38 UTC


README

This module for ZF2 provides a simple service that creates and returns multipart/alternative email messages by simply providing a view script name and a view model|array|traversable to the createMessage() method of the service. The model vars are interpolated into the view script as you'd expect and there's a filter that converts the resultant HTML into plain text automatically.

Although untested, you should be able to pass in the standard template resolver from config so you can easily drop your view scripts into an already available view script path.

REQUIREMENTS

INSTALLATION

The module can be installed with composer. Just add require { "netglue/ng-mtmail" : "dev-master" } to your composer.json file

USAGE

Within your app somewhere... Like in a controller or something,

#!php

use Zend\Mail\Transport\Sendmail;

$sl = $this->getServiceLocator();
$service = $sl->get('MailTemplate');
$model = array(
	'message' => 'How do?',
);
$message = $service->createMessage('example/example', $model);
$message->setSubject('Test Message')
	->addTo('me@example.com')
	->addFrom('me@example.com');

$transport = new Sendmail;
$transport->send($message);

In the default configuration, the view script path is setup to ModuleRoot/view in there is an example template in example/example.phtml hence the example/example parameter to createMessage()

The second parameter to createMessage() is the ViewModel which can be a ready intantiated Zend\View\Model\ViewModel, a Zend\View\Variables object, an array, something that implements Traversable or NULL

You'll have to setup your own transport or get an existing one from the service manager or something...