Skip to content
l2avenholm edited this page Jan 27, 2015 · 5 revisions

Description

Used for work with mail templates. Available management using dashboard crud.

Entity

  • id - entity primary key
  • alias - unique template alias
  • description -template discription
  • subject - mail subject
  • fromEmail - author email
  • fromName - author name
  • bodyHtml - template body html
  • bodyText - template body text
  • created - created timestamp
  • updated - last updated timestamp

Usage

/** @var \Mail\Service\Mail $mailService */
$mailService = $this->getServiceLocator()->get('\Mail\Service\Mail');

/** @var \Mail\Entity\Mail $template */
$template = $mailService->getTemplate('sign-up');

// generate confirm url
$confirmUrl = 'http://your-host/confirm_code';

// asigned value $confirmUrl will replace $template value %confirm%
$mailService->assign($template, 'confirm', $confirmUrl);

/** @var \User\Entity\User $user */
$user = new \User\Entity\User();

// set user email, will be used for setTo() method
$user->setEmail('user@user.com');

// compare $template and $user data and set to the \Zend\Mail\Message()
$message = $mailService->prepareMessage($template, $user);

// send message using \Zend\Mail\Transport\Sendmail()
$mailService->send($message);

Global options

Module is using global options section 'mail':

'mail' => array(
            'transport' => array(
                'options' => array(
                    'host'              => '%host%',
                    'port'              => '%port%',
                ),
            ),
            'message' => array(
                'headers' => array(
                    'PROJECT' => '%project%',
                    'EMAILS'  => '%mail%'
                ),
                'from' => array ('admin@zfury.com')
            )
        )

Additional options

User's sign-up and forgot-password mail are sending from User module by default.
You can set module Mail as default mail sender for all mail including these by adding option to the config:

'mailOptions' => array(
   'useModuleMail' => true
)

Clone this wiki locally