作者:超人 | 来源:互联网 | 2014-05-16 09:11
EMailer是一个简单的封装PHPMailer类。
使用方法
作为普通component:
利用这个例子,使用SMTP作为发送的方法,在控制器创建一个component:
Yii::createComponent('application.extensions.mailer.EMailer');
$mailer->Host = ;
$mailer->IsSMTP();
$mailer->From = 'wei@example.com';
$mailer->AddReplyTo('wei@example.com');
$mailer->AddAddress('qiang@example.com');
$mailer->FromName = 'Wei Yard';
$mailer->CharSet = 'UTF-8';
$mailer->Subject = Yii::t('demo', 'Yii rulez!');
$mailer->Body = $message;
$mailer->Send();
作为application component: 配置文件代码(注意pathViews和pathLayouts参数):
array(
'mailer' => array(
'class' => 'application.extensions.mailer.EMailer',
'pathViews' => 'application.views.email',
'pathLayouts' => 'application.views.email.layouts'
),
// ...
}
控制器代码:
mailer->Host = 'smtp.yiiframework.com';
Yii::app()->mailer->IsSMTP();
Yii::app()->mailer->From = 'wei@pradosoft.com';
Yii::app()->mailer->FromName = 'Wei';
Yii::app()->mailer->AddReplyTo('wei@pradosoft.com');
Yii::app()->mailer->AddAddress('qian@yiiframework.com');
Yii::app()->mailer->Subject = 'Yii rulez!';
Yii::app()->mailer->Body = $message;
Yii::app()->mailer->Send();
原文地址:http://www.yiiframework.com/extension/mailer/