Download the PHP package vernes/yiimailer without Composer

On this page you can find all versions of the php package vernes/yiimailer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package yiimailer

YiiMailer

Yii (v1.1.x) extension for sending emails with layouts using PHPMailer

Features

Installation

  1. Install with composer: composer require vernes/yiimailer
  2. Add 'vendor.vernes.yiimailer.YiiMailer' line to your imports in main and/or console yii config
  3. Copy mail.php config file to protected/config or add configuration array in 'params' under the key 'YiiMailer'
  4. Create email layout file mail.php in protected/views/layouts/ (default path, can be changed in config)
  5. Create all the views you want to use in protected/views/mail/ (default path, can be changed in config)
  6. Put all images you want to embed in emails in images/mail/ (default path, can be changed in config)

Note

In console apps, alias 'webroot' may not be the same as in web apps. See https://github.com/yiisoft/yii/issues/1267. Best workaround is to set alias you need directly in config/console.php, e.g.:

Yii::setPathOfAlias('webroot.images.mail', '/path/to/your/images/mail/dir');

Yet another solution is to override protected/yiic.php and set 'webroot' alias there (see example files).

Usage

Instantiate YiiMailer in your controller or console command and pass view and data array:

$mail = new YiiMailer('contact', array('message' => 'Message to send', 'name' => 'John Doe', 'description' => 'Contact form'));

or

$mail = new YiiMailer();
$mail->setView('contact');
$mail->setData(array('message' => 'Message to send', 'name' => 'John Doe', 'description' => 'Contact form'));

Layout is automatically set from config but you may override it with

$mail->setLayout('layoutName');

Set the properties:

$mail->setFrom('[email protected]', 'John Doe');
$mail->setTo(Yii::app()->params['adminEmail']);
$mail->setSubject('Mail subject');

You may use all PHPMailer properties you would usually use.

And finally send email(s):

if ($mail->send()) {
    Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
} else {
    Yii::app()->user->setFlash('error','Error while sending email: '.$mail->getError());
}

Sending simple messages

You can send email without both the layout and view by using:

$mail = new YiiMailer();
//$mail->clearLayout();//if layout is already set in config
$mail->setFrom('[email protected]', 'John Doe');
$mail->setTo(Yii::app()->params['adminEmail']);
$mail->setSubject('Mail subject');
$mail->setBody('Simple message');
$mail->send();

Alternatively, you may also send email message with layout but without specific view (set layout and set body) or with view but without layout (clear layout and set view).

Setting addresses

When using methods for setting addresses (setTo(), setCc(), setBcc(), setReplyTo()) any of the following is valid for arguments:

$mail->setTo('[email protected]');
$mail->setTo(array('[email protected]','[email protected]'));
$mail->setTo(array('[email protected]'=>'John Doe','[email protected]'));

Sending attachments

You may send one or more attachments using setAttachemnt() method:

$mail->setAttachment('something.pdf');
$mail->setAttachment(array('something.pdf','something_else.pdf','another.doc'));
$mail->setAttachment(array('something.pdf'=>'Some file','something_else.pdf'=>'Another file'));

Test mode

When working locally without mail server installed, it may be useful to save emails as files instead of trying to send them and getting errors in the process. To use test mode, you must specify path to directory where you want to save your emails and set 'testMode' property to 'true' in your config:

    'savePath' => 'webroot.assets.mail',
    'testMode' => true,

Emails are saved as .eml files and you can use software like Mozilla Thunderbird to open them.

Using SMTP

If you want to use SMTP, configure appropriate properties in your config. Example setup for GMail:

    'Mailer' => 'smtp',
    'Host' => 'smtp.gmail.com',
    'Port' => 465,
    'SMTPSecure' => 'ssl',
    'SMTPAuth' => true,
    'Username' => '[email protected]',
    'Password' => 'your_password',

You may also configure this just before sending email:

$mail->setSmtp('smtp.gmail.com', 465, 'ssl', true, '[email protected]', 'your_password');

Examples

Two examples included: one for standard contact form in yii web app and the other one for yii console app.


All versions of yiimailer with dependencies

PHP Build Version
Package Version
Requires php Version >=5.5.0
phpmailer/phpmailer Version ^6.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package vernes/yiimailer contains the following files

Loading the files please wait ....