PHPackages                             pixelcreart/phpmailer - 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. [Mail &amp; Notifications](/categories/mail)
4. /
5. pixelcreart/phpmailer

ActiveYii2-extension[Mail &amp; Notifications](/categories/mail)

pixelcreart/phpmailer
=====================

Phpmailer extension for the Yii framework

1.0.0(2y ago)05BSD-3-ClausePHPPHP &gt;=5.4.0

Since Feb 8Pushed 2y agoCompare

[ Source](https://github.com/pixelcreart/yii2-phpmailer)[ Packagist](https://packagist.org/packages/pixelcreart/phpmailer)[ Docs](https://github.com/pixelcreart/yii2-phpmailer)[ RSS](/packages/pixelcreart-phpmailer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

*IMPORTANT! THIS IS A FORM FROM weijiansdlx/yii2-phpmailer*

yii2-phpmailer
==============

[](#yii2-phpmailer)

Phpmailer extension for the Yii framework yii2-phpmailer
========================================================

[](#phpmailer-extension-for-the-yii-frameworkyii2-phpmailer)

PHPMailer integration for Yii 2 framework
-----------------------------------------

[](#phpmailer-integration-for-yii-2-framework)

### WARNING !!!

[](#warning-)

Breaking backwards compatibility changes were introduced in Yii2 Framework (see [yiisoft/yii2#4071](https://github.com/yiisoft/yii2/issues/4071)).

If you updated after 26.06.2014 your should fix your application config and calls to mail functions (replace `mail` with `mailer`).

In configuration file you should replace:

```
	'components' => [
        'mail' => [
        ...

```

with

```
	'components' => [
        'mailer' => [
        ...

```

In your code replace:

`Yii::$app->mail->...` with `Yii::$app->mailer->...`

(or `Yii::$app->getMail()...` with `Yii::$app->getMailer()...` respectively).

===

This extension adds integration of popular **[PHPMailer](https://github.com/PHPMailer/PHPMailer)** library - a *"full-featured email creation and transfer class for PHP"* - to **[Yii 2 framework](https://github.com/yiisoft/yii2)**.

Although extension classes implement `yii\mail\MailerInterface` and `yii\mail\MessageInterface`, some methods of Yii 2 `BaseMailer` and `BaseMessage` are overriden - mainly because of PHPMailer-specific issues.

Nevertheless - the behavior of the extension should remain expected and predictable and comply interfaces mentioned above (I believe so). If not - feel free to report [issues](https://github.com/SDKiller/zyx-phpmailer/issues).

REQUIREMENTS
------------

[](#requirements)

You should generally follow [Yii 2 requirements](https://github.com/yiisoft/yii2/blob/master/README.md). The minimum is that your Web server supports PHP 5.4.0.

INSTALLATION
------------

[](#installation)

### Install via Composer

[](#install-via-composer)

If you do not have [Composer](http://getcomposer.org/), you may install it by following the instructions at [getcomposer.org](http://getcomposer.org/doc/00-intro.md#installation-nix).

During the extension installation [PHPMailer](https://github.com/PHPMailer/PHPMailer) library will be also installed.

You have two options here - to install latest **stable** release of **PHPMailer** (as of now it is 5.2.8 - many significant issues were solved and improvements made in this release) or install latest development version from **dev-master**.

So, either run

- for PHPMailer stable:

```
php composer.phar require --prefer-dist pixelcreart/phpmailer "~1.0.0"

```

- for dev:

```
php composer.phar require --prefer-dist pixelcreart/phpmailer "~1.0.0"

```

or add respectively:

```
"pixelcreart/phpmailer": "~1.0.0"

```

or

```
"pixelcreart/phpmailer": "~1.0.0"

```

to the require section of your composer.json.

**Note:** this can be affected by 'minimum-stability' settings in your project root composer.json file. If you see error trying to install 'dev-master' branch of PHPMailer you should explicitly point to it, adding

```
"phpmailer/phpmailer": "*"

```

to the require section of composer.json in your project root.

### Install from an Archive File

[](#install-from-an-archive-file)

You may install extension manually. For that purpose you have to download archive file and extract it into `vendor/zyx` directory of your project.

You'll also need to download [PHPMailer](https://github.com/PHPMailer/PHPMailer) library and extract it to `vendor/phpmailer` directory of your project.

**Note:** due to naming agreement 3rd-party extensions and libraries are kept under `vendor` directory.

One of the benefits of installing via Composer is automation of autoload setup. If you install extension and PHPMailer library from archive files, you'll have to setup autoload paths manually.

**Note:** currently PHPMailer does not support namespaces (as its minimum requirements is php 5.0), but provides an SPL-compatible autoloader, and...

> the preferred way of loading the library - just `require '/path/to/PHPMailerAutoload.php';` and everything should work

For further information refer to PHPMailer documentation.

CONFIGURING
-----------

[](#configuring)

To use this extension, you should add some settings in your application configuration file. It may be like the following:

```
return [
//....
	'components' => [
        'mailer' => [
            'class'            => 'pixelcreart\phpmailer\Mailer',
            'viewPath'         => '@common/mail',
            'useFileTransport' => false,
            'config'           => [
                'mailer'     => 'smtp',
                'host'       => 'smtp.yandex.ru',
                'port'       => '465',
                'smtpsecure' => 'ssl',
                'smtpauth'   => true,
                'username'   => 'mysmtplogin@example.ru',
                'password'   => 'mYsmTpPassword',
            ],
        ],
	],
];

```

This is the tipical configuration for sending email via smtp. If you are familiar with PHPMailer, you can see that 'config' array holds settings, similar to corresponding PHPMailer properties. They will be populated when Mailer is initialized.

You can for example define

`'mailer' => 'mail'` or

`'mailer' => 'sendmail', 'sendmail' => '/path/to/sendmail'` - just like in PHPMailer.

You may also configure some default message settings for your application in 'messageConfig' array. They will be populated at the moment of message creation.

For example, you may predefine default contents of 'From' email field - so you will not have to set 'From' it every time when composing message:

```
    ...
    'mailer' => [
        ...
        'messageConfig'    => [
         'from' => ['noreply@example.com' => 'My Example Site']
        ],
        ...
    ],
    ...

```

USAGE
-----

[](#usage)

Example of simple usage:

```
Yii::$app->mailer->compose()
     ->setFrom(['noreply@example.com' => 'My Example Site'])
     ->setTo([$form->email => $form->name])
     ->setSubject($form->subject)
     ->setTextBody($form->text)
     ->send();

```

Example of sending html emails rendering view and layout (assumed that default 'From' is set in application configuration file):

```
Yii::$app->mailer->compose('passwordResetToken', ['user'       => $user,
                                                'title'      => Yii::t('app', 'Password reset'),
                                                'htmlLayout' => 'layouts/html-reset'])
                ->setTo($this->email)
                ->setSubject(Yii::t('app', 'Password reset for ') . Yii::$app->params['siteName'])
                ->send();

```

**Note:** possibility to set 'htmlLayout' dynamically when composing message is not the native behavior of `BaseMailer`. This feature was introduced in this specific extension and is experimental.

For more examples of usage you may refer to documentation on Yii 2 `BaseMailer` and `BaseMessage` and PHPDoc blocks in the extension files.

Additionally some **[Wiki](https://github.com/weijiansdlx/yii2-phpmailer/wiki)** articles are available.

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

820d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9896d4ace701609b96b837fd5ceaeddd040cbb4fd3d71c531e24e17774055493?d=identicon)[mavelar](/maintainers/mavelar)

---

Top Contributors

[![mavelar](https://avatars.githubusercontent.com/u/737470?v=4)](https://github.com/mavelar "mavelar (5 commits)")

---

Tags

mailemailmaileryii2phpmailer

### Embed Badge

![Health badge](/badges/pixelcreart-phpmailer/health.svg)

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

###  Alternatives

[boundstate/yii2-mailgun

Mailgun integration for the Yii framework

28160.6k](/packages/boundstate-yii2-mailgun)[rmrevin/yii2-postman

Mail module for Yii2.

2612.3k](/packages/rmrevin-yii2-postman)[yarcode/yii2-mailgun-mailer

Mailgun mailer implementation for Yii2

1576.0k](/packages/yarcode-yii2-mailgun-mailer)

PHPackages © 2026

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