传智播客旗下技术交流社区北京校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

使用方法
作为普通component:
利用这个例子,使用SMTP作为发送的方法,在控制器创建一个component:
1
2
3
4
5
6
7
8
9
10
11
12
13
$message='Hello World!';
$mailer= 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参数):
1
2
3
4
5
6
7
8
9
'components'=>array(
   'mailer'=>array(
      'class'=>'application.extensions.mailer.EMailer',
      'pathViews'=>'application.views.email',
      'pathLayouts'=>'application.views.email.layouts'
   ),
   // ...
}

控制器代码:
1
2
3
4
5
6
7
8
9
10
11
$message='Hello World!';
Yii::app()->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();


分享至 : QQ空间
收藏

1 个回复

倒序浏览
奈斯
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马