PHPackages                             vernes/yiimailer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. vernes/yiimailer

ActiveYii-extension

vernes/yiimailer
================

Yii extension for sending emails with layouts using PHPMailer

v4.0.1(6y ago)81117.7k—3.8%37[2 issues](https://github.com/vernes/YiiMailer/issues)PHPPHP &gt;=5.5.0

Since Feb 17Pushed 6y ago14 watchersCompare

[ Source](https://github.com/vernes/YiiMailer)[ Packagist](https://packagist.org/packages/vernes/yiimailer)[ RSS](/packages/vernes-yiimailer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (1)Versions (6)Used By (0)

YiiMailer
=========

[](#yiimailer)

Yii (v1.1.x) extension for sending emails with layouts using [PHPMailer](https://github.com/PHPMailer/PHPMailer)

Features
--------

[](#features)

- Based on PHPMailer
- Supports Yii layouts and translation
- Supports web and console applications
- Send full HTML emails with embedded images
- Work with views like you usually do in Yii
- Use test mode to save emails instead of sending them (useful when you don't have mail server installed locally)

Installation
------------

[](#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

[](#note)

In console apps, alias 'webroot' may not be the same as in web apps. See [yiisoft/yii#1267](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
-----

[](#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('from@example.com', '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

[](#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('from@example.com', '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

[](#setting-addresses)

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

```
$mail->setTo('john@example.com');
$mail->setTo(array('john@example.com','jane@example.com'));
$mail->setTo(array('john@example.com'=>'John Doe','jane@example.com'));
```

### Sending attachments

[](#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

[](#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

[](#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' => 'your_email@gmail.com',
	'Password' => 'your_password',
```

You may also configure this just before sending email:

```
$mail->setSmtp('smtp.gmail.com', 465, 'ssl', true, 'your_email@gmail.com', 'your_password');
```

Examples
--------

[](#examples)

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

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity48

Moderate usage in the ecosystem

Community24

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 61.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~643 days

Total

4

Last Release

2542d ago

Major Versions

v2.0 → v3.02018-02-08

v3.0 → v4.02018-06-20

PHP version history (2 changes)v2.0PHP &gt;=5.0.0

v3.0PHP &gt;=5.5.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/f733d5283a578fa96e70e721ec3435c550b5fca4d65556a9d934b948fc25a699?d=identicon)[vernes](/maintainers/vernes)

---

Top Contributors

[![vernes](https://avatars.githubusercontent.com/u/973728?v=4)](https://github.com/vernes "vernes (26 commits)")[![bopinto](https://avatars.githubusercontent.com/u/1161382?v=4)](https://github.com/bopinto "bopinto (5 commits)")[![SaschaScholly](https://avatars.githubusercontent.com/u/7370371?v=4)](https://github.com/SaschaScholly "SaschaScholly (3 commits)")[![xt99](https://avatars.githubusercontent.com/u/608600?v=4)](https://github.com/xt99 "xt99 (2 commits)")[![jcherniak](https://avatars.githubusercontent.com/u/1727656?v=4)](https://github.com/jcherniak "jcherniak (2 commits)")[![ruskid](https://avatars.githubusercontent.com/u/8279841?v=4)](https://github.com/ruskid "ruskid (1 commits)")[![langovoi](https://avatars.githubusercontent.com/u/5055595?v=4)](https://github.com/langovoi "langovoi (1 commits)")[![visavi](https://avatars.githubusercontent.com/u/826831?v=4)](https://github.com/visavi "visavi (1 commits)")[![ferow2k](https://avatars.githubusercontent.com/u/1179833?v=4)](https://github.com/ferow2k "ferow2k (1 commits)")

### Embed Badge

![Health badge](/badges/vernes-yiimailer/health.svg)

```
[![Health](https://phpackages.com/badges/vernes-yiimailer/health.svg)](https://phpackages.com/packages/vernes-yiimailer)
```

###  Alternatives

[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.4k37.3k](/packages/matomo-matomo)[simplesamlphp/simplesamlphp

A PHP implementation of a SAML 2.0 service provider and identity provider.

1.1k12.4M193](/packages/simplesamlphp-simplesamlphp)[getkirby/cms

The Kirby core

1.5k535.5k352](/packages/getkirby-cms)[saithink/saiadmin

webman plugin

2709.9k1](/packages/saithink-saiadmin)[jelix/jelix

Jelix PHP framework

83101.5k4](/packages/jelix-jelix)[doppar/framework

The Doppar Framework

366.7k8](/packages/doppar-framework)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
