ikirux / yii-swift-mailer
Swiftmailer for Yii框架1.x版本的包装器
dev-master
2015-05-18 16:47 UTC
Requires
- swiftmailer/swiftmailer: ~5.0
This package is not auto-updated.
Last update: 2024-09-28 15:54:44 UTC
README
Swiftmailer for Yii框架1.x版本的包装器
当前支持的Swiftmailer版本为5.1.0
它支持以下特性
- smtp、sendmail或邮件传输
- ssl或tls安全性
- 设置To、CC、BCC
- 动态(在运行时生成)和静态文件的附件
- 嵌入文件(静态和动态)
- Swiftmailer插件(AntiFlood、Throtter、Logger)
您可以在http://swiftmailer.org/docs/introduction.html查看官方文档
安装
使用Composer
如果您使用Composer来管理项目依赖,只需将"ikirux/yii-swift-mailer"添加到项目的composer.json文件中。以下是composer.json的示例:
{
"require": {
"ikirux/yii-swift-mailer": "dev-master"
}
}
更多信息请访问https://getcomposer.org.cn/
使用Git
只需将项目克隆到您的扩展目录内
git clone git@github.com:ikirux/Yii-SwiftMailer.git`
配置
通过配置设置yii组件
'mailer' => [
'class' => 'path.to.swiftMailer.SwiftMailer',
// Using SMTP:
'mailer' => 'smtp',
// 'ssl' for "SSL/TLS" or 'tls' for 'STARTTLS'
'security' => 'ssl',
'host' => 'localhost',
'from' => 'admin@localhost',
'username' => 'smptusername',
'password' => '123456',
// Activate the Logger plugin
// more information http://swiftmailer.org/docs/plugins.html#using-the-logger-plugin
//'activateLoggerPlugin' => true,
// Activate the AntiFlood plugin
// more information http://swiftmailer.org/docs/plugins.html#antiflood-plugin
//'activateAntiFloodPlugin' => true,
//'setFloodPluginParams' => ['threshold' => 100, 'sleep' => 30],
// Activate the Throtter plugin
// more information http://swiftmailer.org/docs/plugins.html#throttler-plugin
// Modes support 1 => SwiftMailer::BYTES_PER_MINUTE,
// 2 => SwiftMailer::MESSAGES_PER_SECOND
// 3 => SwiftMailer::MESSAGES_PER_MINUTE
//'activateThrotterPlugin' => true,
//'setThrotterPluginParams' => ['rate' => 10, 'mode' => 3],
],
使用
创建消息
Yii::app()->mailer->setSubject('A great subject')
->addAddress('mail@domain.com')
->setBody('Nice HTML message')
->setAltBody('Message plain text alternative')
->send();
创建具有多个收件人的消息
Yii::app()->mailer->setSubject('A great subject')
->addAddress(['mail@domain.com', 'mail2@domain.com'])
->addCcAddress('mail3@domain.com')
->addBccAddress(['mail4@domain.com', 'mail5@domain.com'])
->setBody('Nice HTML message')
->setAltBody('Message plain text alternative')
->send();
附加文件
Yii::app()->mailer->setSubject('A great subject')
->addAddress('mail@domain.com')
->setBody('Nice HTML message')
->setAltBody('Message plain text alternative')
->addAttachment('/path/to/file.pdf', 'application/pdf', 'Nickname File.pdf')
->addAttachment('/path/to/file.jpg')
->send();
附加动态文件
// Create your file contents in the normal way, but don't write them to disk
$data = create_my_pdf_data();
Yii::app()->mailer->setSubject('A great subject')
->addAddress('mail@domain.com')
->setBody('Nice HTML message')
->setAltBody('Message plain text alternative')
->addDinamicAttachment($data, 'application/pdf', 'FileName.pdf')
->send();
嵌入现有文件
Yii::app()->mailer->setSubject('A great subject')
->addAddress('mail@domain.com')
->setBody(
'<html>' .
' <head></head>' .
' <body>' .
' Here is an image {{image}}' .
' Rest of message' .
' </body>' .
'</html>')
->setAltBody('Message plain text alternative')
->embedFile('{{image}}', '/path/to/file.jpg')
->send();
嵌入动态文件
// Create your file contents in the normal way, but don't write them to disk
$img_data = create_my_image_data();
Yii::app()->mailer->setSubject('A great subject')
->addAddress('mail@domain.com')
->setBody(
'<html>' .
' <head></head>' .
' <body>' .
' Here is an image {{image}}' .
' Rest of message' .
' </body>' .
'</html>')
->setAltBody('Message plain text alternative')
->embedDinamicFile('{{image}}', $img_data, 'image/jpeg', 'image.jpg')
->send();
欢迎您的反馈!
祝您玩得开心!