• Thinkphp3.2邮件发送


    第一步:加入这两个文件

    第二部:在common的function中添加代码

    function think_send_mail($to, $name, $subject = '', $body = '', $attachment = null){
    
        $config = C('THINK_EMAIL');
    
        vendor('PHPMailer.class#phpmailer'); //从PHPMailer目录导class.phpmailer.php类文件
        vendor('SMTP');
        $mail = new PHPMailer(); //PHPMailer对象
    
        $mail->CharSet = 'UTF-8'; //设定邮件编码,默认ISO-8859-1,如果发中文此项必须设置,否则乱码
    
        $mail->IsSMTP(); // 设定使用SMTP服务
    
        $mail->SMTPDebug = $config['SMTPDEBUG']; // 关闭SMTP调试功能
    
    // 1 = errors and messages
    
    // 2 = messages only
    
        $mail->SMTPAuth = true; // 启用 SMTP 验证功能
    
        $mail->SMTPSecure = $config['SMTP_SSL']; // 使用安全协议
    
        $mail->Host = $config['SMTP_HOST']; // SMTP 服务器
    
        $mail->Port = $config['SMTP_PORT']; // SMTP服务器的端口号
    
        $mail->Username = $config['SMTP_USER']; // SMTP服务器用户名
    
        $mail->Password = $config['SMTP_PASS']; // SMTP服务器密码
    
        $mail->SetFrom($config['FROM_EMAIL'], $config['FROM_NAME']);
    
        $replyEmail = $config['REPLY_EMAIL']?$config['REPLY_EMAIL']:$config['FROM_EMAIL'];
    
        $replyName = $config['REPLY_NAME']?$config['REPLY_NAME']:$config['FROM_NAME'];
    
        $mail->AddReplyTo($replyEmail, $replyName);
    
        $mail->Subject = $subject;
    
        $mail->AltBody = "为了查看该邮件,请切换到支持 HTML 的邮件客户端";
    
        $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;
        return $mail->Send() ? true : false;
    
    }

    第三步: 在配置文件中加入以下配置

    //邮件配置
        'THINK_EMAIL' => array(
            'SMTP_SSL'     => '',//是否使用加密协议,使用的话值为ssl
            'SMTP_HOST' => 'smtp.mxhichina.com', //SMTP服务器smtp.mxhichina.com
    
            'SMTP_PORT' => '25', //SMTP服务器端口25
    
            'SMTP_USER' => 'xxx', //SMTP服务器用户名
    
            'SMTP_PASS' => 'xxx', //SMTP服务器密码
    
            'FROM_EMAIL' => 'xxx',
    
            'FROM_NAME' => 'xxx', //发件人名称
    
            'TO_NAME' => 'xxx@qq.com', //发件人名称cdmo@nbinno.com
    
            'REPLY_EMAIL' => '', //回复EMAIL(留空则为发件人EMAIL)
    
            'REPLY_NAME' => '', //回复名称(留空则为发件人名称)
    
            'SESSION_EXPIRE'=>'72',
    
            'SMTPDEBUG'=> '0',//是否开启SMTP调试,0=关闭调试,1 = errors and messages,2 = messages only
        ),

    第四步:控制器中,调用方法

                $moban =
                    '结构式:<img src="http://www.pharmacdmo.com/'.$data['file'].'"><br>'.
                    '产品:'.$data['product_name'].'<br/>'.
                    'cas号:'.$data['cas'].'<br/>'.
                    '数量:'.$data['quantity'].'<br/>'.
                    '纯度:'.$data['purity'].'<br/>'.
                    '交货时间:'.$data['delivery_time'].'<br/>'.
                    '详情:'.$data['other_details'].'<br/>'.
                    '客户名称:'.$data['user_name'].'<br/>'.
                    '公司:'.$data['user_company'].'<br/>'.
                    '电话:'.$data['user_tel'].'<br/>'.
                    '邮箱:'.$data['user_email'].'<br/>'.
                    '主要应用:'.$data['what_app'];
                $to_email = C('THINK_EMAIL.TO_NAME');
    
                think_send_mail($to_email,'','询价信息',$moban);
  • 相关阅读:
    SharePoint 2013中Office Web Apps的一次排错
    如何在Ubuntu上让root帐号可以登录SSH
    如何确定自己的SQL Server的实例是32位的还是64位的?
    [ADO.NET] 如何 使用 OLE DB 讀寫 Excel / 建立 Excel 檔案 (一)
    windows使用nginx实现网站负载均衡测试实例
    jqPlot的Option配置对象详解
    Windows Server 2003安装卡巴斯基2010成功
    Log4Net的使用方法
    在ADO.NET中使用参数化SQL语句的大同小异
    ASP.NET安全问题--Froms验证的具体介绍(中篇)
  • 原文地址:https://www.cnblogs.com/fpcing/p/7573504.html
Copyright © 2020-2023  润新知