网站地图    收藏   

主页 > 后端 > php资料库 >

Yii使用PHPMailer发送邮件实现代码_自学php网

来源:自学PHP网    时间:2014-12-04 22:12 作者: 阅读:

[导读] 使用方法 作为普通component: 利用这个例子,使用SMTP作为发送的方法,在控制器创建一个component: ?php$message = 'Hello World!';$mailer = Yii::createComponent('application.extensions.mailer.EMailer');$mailer-Host...

使用方法

作为普通component:

利用这个例子,使用SMTP作为发送的方法,在控制器创建一个component:

<?php
$message = 'Hello World!';
$mailer = Yii::createComponent('application.extensions.mailer.EMailer');
$mailer->Host = <your smtp 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参数):
 

<?php
'components'=>array(
   'mailer' => array(
      'class' => 'application.extensions.mailer.EMailer',
      'pathViews' => 'application.views.email',
      'pathLayouts' => 'application.views.email.layouts'
   ),
   // ...
}

控制器代码:
 

<?php
$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();


 

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论