rmrevin/yii2-postman Mail module for Yii2.

phpmailermailemailsendingqueue

Mail Extension for Yii2

Installation

In composer.json:

{
    "require": {
        "rmrevin/yii2-postman": "~2.2"
    }
}

configuration

/config/web.php

<?
return [
    // ...
    'components' => [
        // ...
        'postman' => [
            'class' => 'rmrevin\yii\postman\Component',
                'driver' => 'smtp',
                'default_from' => ['mailer@somehost.com', 'Mailer'],
                'subject_prefix' => 'Sitename / ',
                'subject_suffix' => null,
                'table' => '{{%postman_letter}}',
                'view_path' => '/email',
                'smtp_config' => [
                    'host' => 'smtp.domain.cpom',
                    'port' => 465,
                    'auth' => true,
                    'user' => 'email@domain.cpom',
                    'password' => 'password',
                    'secure' => 'ssl',
                    'debug' => false,
                ]
        ],
    ],
    // ...
];

If you want use SMTP without ssl and tsl

 <?
 return [
    // ...
    'components' => [
        // ...
        'postman' => [
            'class' => 'rmrevin\yii\postman\Component',
            // ...
                'smtp_config' => [
                    // ...
                    'secure' => '',
                    'smtpAutoTls' => false,
                ]
        ],
    ],
// ...
];

Updating database schema

After you downloaded and configured yii2-postman, the last thing you need to do is updating your database schema by applying the migrations:

In /config/console.php:

<?
return [
    // ...
    'components' => [
        // ...
        'postman' => [
            'class' => 'rmrevin\yii\postman\Component',
        ],
    ],
    // ...
];

In Command line:

php yii migrate/up --migrationPath=@vendor/rmrevin/yii2-postman/migrations/

Usage

<?
// ...
(new \rmrevin\yii\postman\RawLetter())
    ->setSubject('Subject')
    ->setBody('Message body')
    ->addAddress('user@somehost.com')
    ->addBccAddress(['tech@somehost.com']);
if(!$Letter->send()){
    echo $Letter->getLastError();
}

// path to view algorithm:
// Yii::$app->controller->module->getViewPath() . Postman::$view_path . '/' . 'message-view.php'
// path to view: /protected/views/email/message-view.php
(new \rmrevin\yii\postman\ViewLetter)
    ->setSubject('Subject')
    ->setBodyFromView('letter-view', [
        'name' => 'Rosy',
        'date' => date('Y-m-d')
    ])
    ->addAddress(['user@somehost.com', 'John Smith'])
    ->addAttachment('/path/to/file.tar.gz');
if(!$Letter->send()){
    echo $Letter->getLastError();
}

Cron

In cron script:

LetterModel::cron($num_letters_per_step = 10)

Changelog

2016-03-25 - 2.3.0

  • Update phpmailer to version 5.2.14
  • Bugfix #8
  • Refactoring tests

2015-05-21 - 2.2.4

  • Bugfix #7

2015-05-20 - 2.2.3

  • In method ViewLetter::setViewFromBody add parameter viewPath.

2015-05-13 - 2.2.1

  • In ViewLetter send attribute _subject to view.
  • In LetterModel is off the string length validation.
  • In LetterModel add new property code.

2015-03-04 - 2.1.0

  • In component added params subject_prefix and subject_suffix.
  • Update tests.

Statistics

Downloads
GitHub Stars
GitHub Forks

Releases

Comments



2.4.0 is the latest of 30 releases



BSD-3-Clause license
Stats
26 github stars & 13 github forks
1 downloads in the last day
16 downloads in the last 30 days
11694 total downloads