2017 © Pedro Peláez
 

yii2-extension yii2-swiftmailer

yii2邮件处理类

image

bailangzhan/yii2-swiftmailer

yii2邮件处理类

  • Monday, March 20, 2017
  • by bailangzhan
  • Repository
  • 1 Watchers
  • 2 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

yii2-swiftmailer

此扩展是 Yii2 swiftmailer 邮件类的封装,可直接调用并发送邮件, (*1)

安装

推荐使用composer进行安装, (*2)

$ php composer.phar require bailangzhan/yii2-swiftmailer

或者添加, (*3)

"bailangzhan/yii2-swiftmailer": "^1.0"

到你的composer.json文件的require中, (*4)

使用

配置你的mailer组件

'mailer' => [
    'class' => 'yii\swiftmailer\Mailer',
    'viewPath' => '@common/mail',
    'useFileTransport' => false,
    'transport' => [
        'class' => 'Swift_SmtpTransport',
        'host' => 'smtp address',
        'username' => 'your email username',
        'password' => 'password',
        'port' => '25',
        'encryption' => 'tls',
    ],
    'messageConfig'=>[  
       'charset'=>'UTF-8',  
       'from'=>['your email username' => 'your app name']  
    ],
],

调用Mailer

发送一封邮件

use bailangzhan\Mailer;
$message = [
    'to' => '要发送给谁',
    'subject' => '邮件标题',
    'content' => '邮件内容',
];
$mailer = new Mailer(Mailer::TYPE_1, $messages);
$result = $mailer->sendMessage();

发送模版邮件

$message = [
    'to' => '要发送给谁',
    'subject' => '邮件标题',
    'view' => 'mail-template',
    'params' => [
        'name' => '白狼栈',
    ]
];

发送模版邮件不需要指定content, 但是需要配置模版名, 即view的值,假如你有一个位于 Yii::$app->mailer->viewPath目录下的 mail-template.php 模版,view 填写 mail-template 就好, (*5)

批量发送邮件

$messages = [
    [
        'to' => '要发送给谁',
        'subject' => '邮件标题',
        'content' => '邮件内容',
    ],
    [
        'to' => '要发送给谁',
        'subject' => '邮件标题',
        'content' => '邮件内容',
        'view' => 'mail-template',
        'params' => [
            'name' => '白狼栈',
        ]
    ]
];
$mailer = new Mailer(Mailer::TYPE_2, $messages);
$result = $mailer->sendMessage();

许可

yii2-swiftmailer is released under the BSD 3-Clause License. See the bundled LICENSE.md for details., (*6)

The Versions

20/03 2017

dev-master

9999999-dev

yii2邮件处理类

  Sources   Download

BSD-3

The Requires

 

by manks

yii2 swiftmailer mailer

19/03 2017

1.0.0

1.0.0.0

yii2邮件处理类

  Sources   Download

BSD-3

The Requires

 

by manks

yii2 swiftmailer mailer