zoukankan      html  css  js  c++  java
  • thinkphp 发送邮件

    将PHPMailer.class.php 和 Smtp.class.php放在ThinkPHPLibraryVendor下
    引用 PHPmailer文件
    function send_mail_local($to = '', $subject = '', $body = '', $name = '', $attachment = null)
    {
    $from_email =C('MAIL_SMTP_USER');//"415569142@qq.com";
    $from_name = "达人德州扑克官网";
    $reply_email = '';
    $reply_name = '';
    echo C('MAIL_SMTP_USER');
    //require_once('./ThinkPHP/Library/Vendor/PHPMailer/phpmailer.class.php');增加命名空间,可以注释掉此行
    $mail = new PHPMailer(); //实例化PHPMailer
    $mail->CharSet = 'UTF-8'; //设定邮件编码,默认ISO-8859-1,如果发中文此项必须设置,否则乱码
    $mail->IsSMTP(); // 设定使用SMTP服务
    $mail->SMTPDebug = 1; // 关闭SMTP调试功能
    // 1 = errors and messages
    // 2 = messages only
    $mail->SMTPAuth = true; // 启用 SMTP 验证功能

    $mail->SMTPSecure = ''; // 使用安全协议
    $mail->Host =C('MAIL_SMTP_HOST');//"smtp.163.com"; // SMTP 服务器
    $mail->Port = C('MAIL_SMTP_PORT');//25; // SMTP服务器的端口号
    $mail->Username =C('MAIL_SMTP_USER');//"415569142@qq.com" ; // SMTP服务器用户名
    $mail->Password = C('MAIL_SMTP_PASS');//"zhengfeng01"; // SMTP服务器密码
    $mail->SetFrom($from_email, $from_name);
    $replyEmail = $reply_email ? $reply_email : $from_email;
    $replyName = $reply_name ? $reply_name : $from_name;
    if ($to == '') {
    $to = C('MAIL_SMTP_CE'); //邮件地址为空时,默认使用后台默认邮件测试地址
    }
    if ($name == '') {
    $name = "1"; //发送者名称为空时,默认使用网站名称
    }
    if ($subject == '') {
    $subject = "1"; //邮件主题为空时,默认使用网站标题
    }
    if ($body == '') {
    $body = "1"; //邮件内容为空时,默认使用网站描述
    }
    $mail->AddReplyTo($replyEmail, $replyName);
    $mail->Subject = $subject;
    $mail->MsgHTML($body); //解析
    $mail->AddAddress($to, $name);
    if (is_array($attachment)) { // 添加附件
    foreach ($attachment as $file) {
    is_file($file) && $mail->AddAttachment($file);
    }
    }

    return $mail->Send() ? true : $mail->ErrorInfo; //返回错误信息
    }

  • 相关阅读:
    电脑护眼模式参数
    五险一金的常识
    python安装失败0x80240017
    安装Win7提示Windows无法安装到磁盘怎么办
    windows无法安装到这个磁盘怎样解决
    华硕笔记本BIOS设置详解
    eclipse运行一个类却运行的是另外一个类,报无法加载的类
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
  • 原文地址:https://www.cnblogs.com/zfeng/p/4670723.html
Copyright © 2011-2022 走看看