Giter Club home page Giter Club logo

yii2-swiftmailer's Introduction

yii2-swiftmailer

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

安装

推荐使用composer进行安装

$ php composer.phar require bailangzhan/yii2-swiftmailer

或者添加

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

到你的composer.json文件的require

使用

配置你的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 就好

批量发送邮件

$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.

yii2-swiftmailer's People

Contributors

bailangzhan avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

lb491798689

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.