rmrevin/yii2-postman 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rmrevin/yii2-postman

最新稳定版本:2.4.0

Composer 安装命令:

composer require rmrevin/yii2-postman

包简介

Mail module for Yii2.

README 文档

README

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)

统计信息

  • 总下载量: 12.2k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 29
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 26
  • Watchers: 7
  • Forks: 13
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2013-05-31