Bizley
(Bizley)
September 2, 2014, 6:50pm
1
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.
Bizley
(Bizley)
October 26, 2014, 12:23pm
3
Please upgrade your version to 1.11 (available here or at GitHub).
Typo in code fixed.
Bizley
(Bizley)
November 1, 2014, 7:15pm
4
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)).
Bizley
(Bizley)
February 11, 2015, 8:31am
5
Version 1.3 is available with PHPMailer updated to 5.2.9.
Bizley
(Bizley)
February 24, 2015, 9:13am
6
Version 1.4 is available now with attachments methods and helper methods for adding many recipients at once.
Bizley
(Bizley)
May 11, 2015, 9:44am
7
Multimailer has been updated to v1.4.1 with PHPMailer 5.2.10.
Bizley
(Bizley)
May 27, 2015, 7:10am
8
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/
Bizley
(Bizley)
December 7, 2015, 8:53am
9
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/