Skip to content
RWOverdijk edited this page Jan 30, 2013 · 5 revisions

Using this module has been made ridiculously simple. After configuring the module you're ready to roll.

<?php

// This is the service. It only has two methods.
$mail = $serviceManager->get('SxMail\Service\SxMail');

// This methods fetches the merged configuration for the specified $configKey.
// If left empty, defaults to default. Normally, you won't ever need this method.
$configuration = $mail->getConfig($configKey = null);

// This returns the SxMail instance you'll be working with, configured and ready to go.
$sxMail = $mail->prepare($configKey = null);

// Set the layout to use. 
// you'd use this if you decide to not use the layout from the config, or none has been set in the config.
// This method accepts thee input types:
//  - null                          Tries to use the layout from the config.
//  - Zend\View\Model\ViewModel     Sets the viewModel as layout
//  - string                        Uses string to locate (resolve to) a layout.
// The body will be set using property "content". So to get the body in the layout use $this->content
$sxMail->setLayout($template = null);

// Get the layout. You might want to set some variables on the layout ViewModel.
$sxMail->getLayout();

// This returns A Zend\Mail\Message. It accepts thee input types:
//  - null                          Converts body to an empty string
//  - Zend\View\Model\ViewModel     Renders the ViewModel
//  - string                        Uses string as body
// If you have configured a layout, the content of $body will be passed to the layout
// in key content. So in your layout, you can use $this->content to get the body.
$message = $sxMail->compose($body = null);

// This sends the email. Pretty simple.
$sxMail->send($message);

Clone this wiki locally