原文链接 : http://www.yiiframework.com/extension/mailer/
下载插件放在 :XXX/protected/extensions/
作为一个普通的组建使用 :
<?php
$message = 'Hello World!';
$mailer = Yii::createComponent('application.extensions.mailer.EMailer');
$mailer->Host = 'smtp.163.com';
$mailer->SMTPAuth = true;
$mailer->IsSMTP();
$mailer->From = 'FROM@example.com';
$mailer->AddReplyTo('FROM@example.com');
$mailer->AddAddress('TO@example.com');
$mailer->Username = 'FROM@163.com';
$mailer->Password = 'XXXXX';
$mailer->FromName = 'XXX';
$mailer->CharSet = 'UTF-8';
$mailer->Subject = Yii::t('demo', 'Yii rulez!');
$mailer->Body = $message;
$mailer->Send();
作为一个应用组建使用 :
在yii的config/main 里面 增加一下代码
<?php
'components'=>array(
'mailer' => array(
'class' => 'application.extensions.mailer.EMailer',
'pathViews' => 'application.views.email',
'pathLayouts' => 'application.views.email.layouts'
),
// ...
}
然后在controller:
<?php
$message = 'Hello World!';
Yii::app()->mailer->Host = 'smtp.163.com';
Yii::app()->mailer->SMTPAuth = true;
Yii::app()->mailer->IsSMTP();
Yii::app()->mailer->From = 'FROM@example.com';
Yii::app()->mailer->FromName = 'XXX';
Yii::app()->mailer->Username = 'FROM@example.com';
Yii::app()->mailer->Password = 'XXX';
Yii::app()->mailer->AddReplyTo('FROM@example.com');
Yii::app()->mailer->AddAddress('TO@example.com');
Yii::app()->mailer->Subject = 'Yii rulez!';
Yii::app()->mailer->CharSet = 'UTF-8';
Yii::app()->mailer->Body = $message;
Yii::app()->mailer->Send();
PS:QQ发送邮件比较麻烦,不作演示