Skip to content

Configuration options

Wesley Overdijk edited this page Jul 31, 2013 · 9 revisions

This module is easy to configure. I'll list some examples to get you familiar with the way things work.


Setting up transport

Setting up a transport method is pretty simple. By default, meaning with no configuration, this module assumes, and thus uses Sendmail.

Configuring any transport method, is done like this:

<?php
return array(
    'sxmail' => array(
        'configs' => array(
            'default' => array(
                'transport' => array(
                    'type'      => 'smtp',
                    'options'   => array(
                        'name'              => 'localhost.localdomain',
                        'host'              => '127.0.0.1',
                        'connection_class'  => 'login',
                        'connection_config' => array(
                            'username' => 'user',
                            'password' => 'pass',
                        ),
                    ),
                ),
            ),
        ),
    ),
);

You can find the configuration options in the zf2 documentation of Zend\Mail.

Setting up multiple configurations

This module allows you to setup multiple mailing configs. This way, you can setup default configuration (see example above) for smtp, and set message specific configuration in separate configurations. The values in other configurations overwrite those in the default.

<?php
return array(
    'sxmail' => array(
        'configs' => array(
            'default' => array(
                'transport' => array(
                    'type'      => 'smtp',
                    'options'   => array(
                        'name'              => 'localhost.localdomain',
                        'host'              => '127.0.0.1',
                        'connection_class'  => 'login',
                        'connection_config' => array(
                            'username' => 'user',
                            'password' => 'pass',
                        ),
                    ),
                ),
            ),
            'otherMailing' => array(
                'transport' => array(
                    'type'      => null,        // null defaults to Sendmail
                    'type'      => 'sendmail',  // Purely for illustration
                    'options'   => null,        // Options would get ignored anyway.
                ),
            ),
        ),
    ),
);

Configuring the message

It's possible to configure messages, too. It accepts options, headers and a layout name. Here's an example:

<?php
return array(
    'sxmail' => array(
        'configs' => array(
            'default' => array(
                'message' => array(
                    'layout'  => 'myLayout.phtml',
                    'headers' => array(
                        'X-Powered-By'      => 'ZF2 and SxMail',
                        'List-Unsubscribe'  => '<mailto:unsubscribe-listname-12345@example.com>, '+
                                               '<http://example.com/unsubscribe/?listname=listname@example.com?id=12345>',
                    ),
                    'options' => array(
                        'to'    => 'recipient@example.com',
                        'from'  => 'sender@example.com',
                    ),
                ),
            ),
        ),
    ),
);

layout

If layout has been set, this will be used to wrap the email. So basically it acts like you'd expect a layout file to behave.

Note: It will look for the layout file in the defined paths. So make sure that you've configured the resolver correctly.

generate_alternative_body

Setting this to false will prevent the module from creating an alternative body for your message. The alternative body will only be added when the mime-type is set to text/html or when it has been detected as 'text/html`.

headers

Headers will be added as expected. basic $key=>$value pairs are expected. Anything else will throw an Exception.

options

All of the other options, are basically for the lazy people. Every mail message allows you to set a couple of things. Methods like setSubject, setFrom and setTo. This allows you to just define to and the module calls setTo for you. You can find all methods here.