Yii-Multimailer Extension

Yii-MultiMailer allows you to send email with the help of PHPMailer class or to store emails in database (to send them later using Java workers for example). You can use templates for email body if needed.

http://www.yiiframework.com/extension/multimailer/

See Yii-MultiMailer on GitHub: https://github.com/bizley-code/Yii-MultiMailer

How to use it:


$mailer = Yii::app()->MultiMailer->to('example@server.com', 'Recipient');

$mailer->subject('Example email subject');

$mailer->body('<h1>Hello</h1><p>This is test.<br>MultiMailer test.</p>');


if ($mailer->send()) {

    // success

}

else {

    // error

}

You can chain the methods like:


Yii::app()->MultiMailer->to('example@server.com', 'Recipient')->subject('Example email subject')->body('<h1>Hello</h1><p>This is test.<br>MultiMailer test.</p>')->send();

Database emails storage:

You can use MultiMailer to save email in database instead of sending it immediately. Email will be prepared using the PHPMailer as well.

First the configuration:


return array(

    'components' => array(

        'MultiMailer' => array(

            'class' => 'ext.MultiMailer.MultiMailer',

            'setFromAddress' => 'from@yourwebsite.com',

            'setFromName' => 'Your Website',

            'setMethod' => 'DB',

            'setDbModel' => 'Email',

        ),

    ),

);

You need to prepare the database table for email storage with Active Record model class (‘Email’ in the example above). Default table columns are:

  • ‘email’

  • ‘name’

  • ‘subject’

  • ‘body’

  • ‘alt’

See the documentation for information about adding or switching the columns off.

The usage in this case is the same as before but remember that method send() will not actually send the email but will save it in database.

Changes in version 1.1:

  • added Gmail method

  • added Sendmail method

  • added qmail method

  • added POP before SMTP method

  • added CC and BCC methods

  • fixed error with saving multiple emails to database when adding multiple recipients with the same email address

Please upgrade your version to 1.11 (available here or at GitHub).

Typo in code fixed.

Version 1.2 is available:

  • New method db() for altering DB model columns

  • Messages are now translated with Yii::t() (can be switched off)

  • DB model validation errors can be tracked now with getMultiError(true)

About db() method.

Until v1.2 you could alter DB model parameters in config file like this:




return array(

    'components' => array(

        'MultiMailer' => array(

            'class'             => 'ext.MultiMailer.MultiMailer',

            'setFromAddress'    => 'example@example.com',

            'setFromName'       => 'Example',

            'setMethod'         => 'DB',

            'setDbModel'        => 'Email',

            'setDbModelColumns' => array(

                'alt'       => null,

                'email'     => 'address',

                'others'    => array(

                    'status' => 'pending',

                ),

            ),

        ),

        // ...

    ),

    // ...

);



This configuration means:

  • column ‘alt’ is not present in DB model, skip it

  • column for storing email address is named ‘address’ in DB model, not ‘email’

  • additional column ‘status’ should be saved with value ‘pending’

In v1.2 this still works but the problem is what to do if we want to set status ‘sent’ for one of the emails?

Before v1.2 you could only alter column for single instance by changing the $setDbModelColumns like:




$mailer = Yii::app()->MultiMailer;

$mailer->setDbModelColumns['others']['status'] = 'sent';



Now you can use db() method for this.




$mailer = Yii::app()->MultiMailer;

$mailer->db('status', 'sent');



You can alter single column with db($name, $value) parameters or set many of them using the array db(array($name1 => $value1, $name2 => $value2)).

Version 1.3 is available with PHPMailer updated to 5.2.9.

Version 1.4 is available now with attachments methods and helper methods for adding many recipients at once.

Multimailer has been updated to v1.4.1 with PHPMailer 5.2.10.

Version 1.5 released:

  • PHPMailer class is now extended with ProxyPHPMailer class.

  • Library files are included using Yii::import() now.

  • New property ‘setPattern’ allows to set validation pattern for PHPMailer in case of problems with PCRE8 regex (default ‘auto’).

  • New public method ‘getPhpmailer()’ allows to control PHPMailer directly.

  • New public method ‘clearAllRecipients()’ allows to remove all recipients (including CC and BCC recipients)

  • Method ‘_processBody()’ is using Yii::renderFile() instead of Yii::renderPartial() in case of command line action and properly throws exception instead of using ‘setMultiError()’

http://www.yiiframework.com/extension/multimailer/

Version 1.6 released with PHPMailer 5.2.14.

This is the last version of MultiMailer (excluding bug fixes).

If you would like to upgrade PHPMailer version from now on just replace the content of PHPMailer folder but test it every time because something might not work properly.

http://www.yiiframework.com/extension/multimailer/