zoukankan      html  css  js  c++  java
  • yii 使用 phpmailer发送邮件

    原文链接 :  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发送邮件比较麻烦,不作演示

  • 相关阅读:
    常用数据结构之字符串
    c++知识点总结--友元&运算符重载
    c++知识点总结-模板特化
    c++知识点总结--new的一些用法
    linux socket c/s上传文件
    STL之算法使用简介
    【bzoj2733】 HNOI2012—永无乡
    【bzoj3132】 Sdoi2013—森林
    【bzoj1483】 HNOI2009—梦幻布丁
    【bzoj3091】 城市旅行
  • 原文地址:https://www.cnblogs.com/weishuan/p/5210839.html
Copyright © 2011-2022 走看看