janisto / yii-mailer
Swift Mailer 的 Yii 组件
1.0.0
2013-11-15 15:40 UTC
Requires
- php: >=5.1.0
- swiftmailer/swiftmailer: >=5.0.0
This package is not auto-updated.
Last update: 2024-09-23 16:06:28 UTC
README
Swift Mailer 的 Yii 组件
要求
- Yii 1.1.14 或更高版本
- Composer
安装
- 需要此包。
{ "name": "app-name", "description": "App description", "type": "project", "prefer-stable": true, "require": { "php": ">=5.3.0", "yiisoft/yii": "1.1.14", "janisto/yii-mailer": "1.0.0" } }
- 在您的入口脚本(index.php 和/或 yiic.php)中包含 Composer 自动加载器,在 Yii 之前。
// Composer autoload $composerAutoload = dirname(__FILE__) . '/../vendor/autoload.php'; require_once($composerAutoload); ...
- 将供应商路径添加到您的配置文件中,附加组件并设置属性。
'aliases'=>array( 'vendor' => realpath(__DIR__ . '/../../vendor'), ), 'components' => array( ... 'mailer' => array( 'class' => 'vendor.janisto.yii-mailer.SwiftMailerComponent', 'type' => 'smtp', 'host' => 'email-smtp.us-east-1.amazonaws.com', 'port' => 587, 'username' => 'xxx', 'password' => 'yyy', 'security' => 'tls', 'throttle' => 5*60, ), ... ),
使用
$message = Yii::app()->mailer ->createMessage('Your subject', 'Here is the message itself') ->setFrom(array('from@domain.com' => 'From Name')) ->setTo(array('to@domain.com' => 'To Name')); Yii::app()->mailer->send($message);
或
$failures = array(); $sent = 0; $from = array('from@domain.com' => 'From Name'); $emails = array( array('to@domain.com' => 'To Name'), array('receiver@bad-domain.org' => 'To Name'), array('other-receiver@bad-domain.org' => 'To Name'), ); /* @var Swift_Message $message */ $message = Yii::app()->mailer ->createMessage('Your subject') ->setFrom($from) ->setBody('Here is the message itself') ->addPart('<q>Here is the message itself</q>', 'text/html'); foreach ($emails as $to) { $message->setTo($to); try { $sent += Yii::app()->mailer->send($message, $failures); } catch (Exception $e) { // SMTP server not responding or limit exceeded? echo $e->getMessage(); } } echo "$sent emails sent.\n"; echo "Failures:\n"; print_r($failures);
变更日志
v1.0.0
- 初始版本。
许可
yii-mailer 是免费且不受限制的 公共领域 软件。