Version 1.2.0 Created by the goalio UG (haftungsbeschränkt)
Provide configurable Mail Transport Factory and simple messaging for ZF2
- Zend Framework 2 (> 2.3.3).
- Configure transport service for using Zend\Mail [COMPLETE]
With ZF2.3 the Transport Factory changed. This made changes to the configuration in the goaliomailservice.global.php (and goaliomailservice.local.php) neccessary. I tried to check this in my own factory, but please be aware of this.
-
Add this project and the requirements in your composer.json:
"require": { "goalio/goalio-mailservice": "1.*" }
-
Now tell composer to download GoalioMailService by running the command:
$ php composer.phar update
-
Enabling it in your
application.config.php
file.<?php return array( 'modules' => array( // ... 'GoalioMailService' ), // ... );
-
Copy the configuration files for local and global from
./vendor/goalio/goalio-mailservice/config/goaliomailservice.{local,global}.php.dist
to./config/autoload/goaliomailservice.{local,global}.php
and change the values as desired. -
If you are using the FileTransport (for development) create the directory
./data/mail
.
// The template used by the PhpRenderer to create the content of the mail
$viewTemplate = 'module/email/testmail';
// The ViewModel variables to pass into the renderer
$value = array('foo' => 'bar');
$mailService = $this->getServiceManager()->get('goaliomailservice_message');
$message = $mailService->createTextMessage($from, $to, $subject, $viewTemplate, $values);
$mailService->send($message);
GoalioMailService uses sendmail by default, but you can set it up to use SMTP by putting your information in the config file like this:
$settings = array(
'type' => 'Zend\Mail\Transport\Smtp',
'options_class' => 'Zend\Mail\Transport\SmtpOptions',
'options' => array(
'host' => 'smtp.gmail.com',
'connection_class' => 'login',
'connection_config' => array(
'ssl' => 'tls',
'username' => 'YOUR-USERNAME-HERE@gmail.com',
'password' => 'YOUR-PASSWORD-HERE'
),
'port' => 587
)
);