• 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发送邮件比较麻烦,不作演示

  • 相关阅读:
    不可重叠最长重复子串
    离散化
    hash是一门优雅的暴力
    Detect the Virus (字符串转化+AC自动机)
    病毒侵袭(AC自动机变形)
    hdu2069(Coin Change)
    Hie with the Pie(poj3311)
    poj3254(状压dp入门第一道题,很详细)
    map系统学习
    ACM-ICPC 2018 南京赛区网络预赛 B. The writing on the wall
  • 原文地址:https://www.cnblogs.com/weishuan/p/5210839.html
Copyright © 2020-2023  润新知