zoukankan      html  css  js  c++  java
  • ThinkPHP邮件发送函数示例

    ThinkPHP邮件发送函数示例详解
    1. /**
    2.  * 发送邮件
    3.  * @param $tomail
    4.  * @param $subject
    5.  * @param $body
    6.  * @param string $config
    7.  * @return bool
    8.  * @throws Exception
    9.  * @throws phpmailerException
    10.  * www.shouce.ren
    11.  */
    12. function sendmail($tomail,$subject,$body){
    13.     import('Common.ORG.PHPMailer.PHPMailer');
    14.     $mail = new CommonORGPHPMailerPHPMailer();
    15.     if(C('mail_type')){
    16.         $mail->IsSMTP();
    17.     }elseif(C('mail_type')==2){
    18.         $mail->IsMail();
    19.     }else{
    20.         if(C('sendmailpath')){
    21.             $mail->Sendmail = C('mail_sendmail');
    22.         }else{
    23.             $mail->Sendmail =ini_get('sendmail_path');
    24.         }
    25.         $mail->IsSendmail();
    26.     }
    27.     if(C('mail_auth')){
    28.         $mail->SMTPAuth = true; // 开启SMTP认证
    29.     }else{
    30.         $mail->SMTPAuth = false; // 开启SMTP认证
    31.     }
    32.     $mail->CharSet='utf-8';
    33.     $mail->SMTPDebug  = false;        // 改为2可以开启调试
    34.     $mail->SMTPAuth   = true;
    35.     $mail->Host = C('mail_server');      // GMAIL的SMTP
    36.     $mail->Port = C('mail_port');    // GMAIL的SMTP端口号
    37.     $mail->Username = C('mail_user'); // GMAIL用户名,必须以@gmail结尾
    38.     $mail->Password = C('mail_password'); // GMAIL密码
    39.     $mail->SetFrom(C('mail_from'), C('site_name'));     //发送者邮箱
    40.     $mail->AddAddress($tomail);
    41.     $mail->IsHTML(true); // 以HTML发送
    42.     $mail->Subject = $subject;
    43.     $mail->Body = $body;
    44.     if(!$mail->Send())
    45.     {
    46.         return false;
    47.     }else{
    48.         return true;
    49.     }
    50. }
  • 相关阅读:
    MFC编程习惯
    光源的频闪与常亮
    相机的选择——卷帘快门(Rolling Shutter)与全局快门(Global Shutter)
    Halcon标定(以40*40标定板为例)
    DALSA线阵相机使用教程(以16K为例)、保存配置文件ccf细节
    打包exe(使用Inno Setup)
    机器视觉项目总结——镜头
    Qt(MinGW版本)utf8终端中文乱码解决方案
    Qt(MinGW版本)安装
    (C#)Windows Shell 外壳编程系列7
  • 原文地址:https://www.cnblogs.com/ZDPPU/p/5823813.html
Copyright © 2011-2022 走看看