In composer.json
:
{
"require": {
"rmrevin/yii2-postman": "~2.0"
}
}
/config/web.php
<?
return [
// ...
'components' => [
// ...
'postman' => [
'class' => 'rmrevin\yii\postman\Component',
'driver' => 'smtp',
'default_from' => ['[email protected]', 'Mailer'],
'table' => '{{%postman_letter}}',
'view_path' => '/email',
'smtp_config' => [
'host' => 'smtp.domain.cpom',
'port' => 465,
'auth' => true,
'user' => '[email protected]',
'password' => 'password',
'secure' => 'ssl',
'debug' => false,
]
],
],
// ...
];
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/
<?
// ...
(new \rmrevin\yii\postman\RawLetter())
->setSubject('Subject')
->setBody('Message body')
->addAddress('[email protected]')
->addBccAddress(['[email protected]']);
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')
->setBodyView('letter-view', [
'name' => 'Rosy',
'date' => date('Y-m-d')
])
->addAddress(['[email protected]', 'John Smith'])
->addAttachment('/path/to/file.tar.gz');
if(!$Letter->send()){
echo $Letter->getLastError();
}
In cron script:
LetterModel::cron($num_letters_per_step = 10)