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. }
  • 相关阅读:
    ajax专题
    luogu P1346 电车 最短路
    luogu P1462 通往奥格瑞玛的道路 最短路
    luogu P1328 生活大爆炸版石头剪刀布
    luogu P1315 联合权值 枚举
    luogu P1156 垃圾陷阱 背包问题
    luogu P1217 回文质数 枚举
    luogu P3650 滑雪课程设计 枚举
    luogu1209 修理牛棚 贪心
    luogu P1223 排队接水 贪心
  • 原文地址:https://www.cnblogs.com/ZDPPU/p/5823813.html
Copyright © 2011-2022 走看看