• 邮件发送


    /**
    * 邮件发送
    * @param $to 接收人
    * @param string $subject 邮件标题
    * @param string $content 邮件内容(html模板渲染后的内容)
    * @throws Exception
    * @throws phpmailerException
    */
    function send_email($to,$subject='',$content=''){
    require_once THINK_PATH.'Library/Vendor/phpmailer/PHPMailerAutoload.php';
    $mail = new PHPMailer;
    $config = tpCache('smtp');//获取文件里面的参数
    $mail->CharSet = 'UTF-8'; //设定邮件编码,默认ISO-8859-1,如果发中文此项必须设置,否则乱码
    $mail->isSMTP();
    //Enable SMTP debugging
    // 0 = off (for production use)
    // 1 = client messages
    // 2 = client and server messages
    $mail->SMTPDebug = 0;
    //调试输出格式
    //$mail->Debugoutput = 'html';
    //smtp服务器
    $mail->Host = $config['smtp_server'];
    //端口 - likely to be 25, 465 or 587
    $mail->Port = $config['smtp_port'];

    if($mail->Port === 465) $mail->SMTPSecure = 'ssl';// 使用安全协议
    //Whether to use SMTP authentication
    $mail->SMTPAuth = true;
    //用户名
    $mail->Username = $config['smtp_user'];
    //密码
    $mail->Password = $config['smtp_pwd'];
    //Set who the message is to be sent from
    $mail->setFrom($config['smtp_user']);
    //回复地址
    //$mail->addReplyTo('replyto@example.com', 'First Last');
    //接收邮件方
    if(is_array($to)){
    foreach ($to as $v){
    $mail->addAddress($v);
    }
    }else{
    $mail->addAddress($to);
    }

    $mail->isHTML(true);// send as HTML
    //标题
    $mail->Subject = $subject;
    //HTML内容转换
    $mail->msgHTML($content);
    //Replace the plain text body with one created manually
    //$mail->AltBody = 'This is a plain-text message body';
    //添加附件
    //$mail->addAttachment('images/phpmailer_mini.png');
    //send the message, check for errors
    return $mail->send();
    }
  • 相关阅读:
    shell脚本的分发,测试,查看
    shell 脚本获取cpu信息(转载)
    shell 脚本编写之获取字符串长度(转载)
    service
    关于Linux安装中NAT模式和桥接模式的区别详解(转载)
    kdj
    pod 详解
    k8s基本概念,资源对象
    AliOS Things添加环境变量
    子函数通过一级指针访问二维数组
  • 原文地址:https://www.cnblogs.com/lixiuyuan999/p/6368427.html
Copyright © 2020-2023  润新知