multimailer Yii extension for sending or saving emails with templates and attachments.

  1. What it does
  2. The last version
  3. Installation
  4. How to use it
  5. Special case: emails in database
  6. List of quick-start extension methods
  7. Requirements
  8. Resources
  9. Added in version 1.6
  10. Added in version 1.5
  11. Added in version 1.4.1
  12. Added in version 1.4
  13. Added in version 1.3
  14. Added in version 1.2
  15. Added in version 1.1

What it does

This extension allows to send emails with the help of PHPMailer class or to store emails in database (to send them later using Java workers for example).

The last version

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

This version does not include PHPMailer files because with the last critical issue being fixed I don't want to open your server to exploits with older versions. Please get the latest version of PHPMailer at https://github.com/PHPMailer/PHPMailer and place all the folders and files in MultiMailer/PHPMailer folder. I recommend switching to Yii 2.

Installation

Place the MultiMailer folder inside your Yii /protected/extensions directory. Modify the main.php config file. For example:

return array(
    'components' => array(
        'MultiMailer' => array(
            'class' => 'ext.MultiMailer.MultiMailer',
            'setFromAddress' => 'from@yourwebsite.com',
            'setFromName' => 'Your Website',
        ),
    ),
);

This sets MultiMailer to send email using PHP mail() function with sender 'Your Website from@yourwebsite.com'. You can find more configuration examples in Examples folder.

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 (except attachment() and attachments()) 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();

Special case: emails in database

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.

List of quick-start extension methods

  • attachment() - add an attachment (option: attachments() - add the list of attachments)
  • bcc() - add a blind carbon copy recipient (options: bccs() - add the list of bcc recipients)
  • body() - set the email body text (option: set the list of prameters for template here and use template() to add template)
  • cc() - add a carbon copy recipient (option: ccs() - add the list of cc recipients)
  • send() - send the email
  • subject() - set the email subject
  • to() - add a recipient (option: tos() - add the list of recipients)

Requirements

Yii 1.1 or above.

Resources

Source code:

Added in version 1.6

  • PHPMailer updated to 5.2.14

Added in version 1.5

  • 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().

Added in version 1.4.1

  • PHPMailer updated to 5.2.10

Added in version 1.4

  • new methods for adding attachments and group lists of recipients
  • new parameter setLanguage - sets the language for PHPMailer errors with optional language data file. Default language is English (en).

Added in version 1.3

  • PHPMailer updated to 5.2.9

Added in version 1.2

  • additional method for altering DB model columns
  • messages are translated with Yii:t now (can be switched off)
  • DB model validation errors can be tracked now with getMultiError(true)

Added in version 1.1

  • Gmail method
  • Sendmail method
  • qmail method
  • POP before SMTP method
  • CC and BCC headers
0 0
2 followers
1 097 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: Mail
Developed by: Bizley
Created on: Sep 5, 2014
Last updated: 7 years ago

Downloads

show all

Related Extensions