zoukankan      html  css  js  c++  java
  • ThinkPHP 通过 PHPMailer插件来发送邮件

    1、修改 application 中的 common.php 文件

    use PHPMailerPHPMailerPHPMailer;
    
    function email($mailto, $subject, $content)
    {
        // 实列化PHPMailer,同时传递true表示启用异常机制
        $mail = new PHPMailer(true);
        try {
            $mail->SMTPDebug = 0;                                 // 启用调试
            $mail->isSMTP();                                      // 设置mailer使用简单的邮件传输协议
            $mail->Host = 'smtp.163.com';                         // Specify main and backup SMTP servers
            $mail->SMTPAuth = true;                               // Enable SMTP authentication
            $mail->Username = '邮箱名';                   // SMTP username
            $mail->Password = '密码';                         // SMTP password
            $mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
            $mail->Port = 465;                                    // TCP port to connect to
            $mail->CharSet = 'utf-8';
    
            //Recipients
            $mail->setFrom('getcharzhaopan@163.com', 'GetcharZp');
            $mail->addAddress($mailto);                           // 发送到的目标邮箱
            //Content
            $mail->isHTML(true);                           // Set email format to HTML
            $mail->Subject = $subject;                            // 发送邮箱的标题
            $mail->Body    = $content;                            // 发送邮箱的正文
    
            return $mail->send();
        }catch (Exception $e) {
            exception($mail->ErrorInfo, 1001);
        }
    }

    2、在 Controller 和 Modal 中都阔以直接使用 email 方法了

  • 相关阅读:
    Effective C++第三遍
    SQL基础教程
    hibernate 数据关联多对多
    hibernate 数据关联一对一
    hibernate 数据关联一对多
    hibernate Criteria查询
    hibernate HQL查询
    hibernate 持久化对象的生命周期
    hibernate的配置
    微博登录
  • 原文地址:https://www.cnblogs.com/GetcharZp/p/12368293.html
Copyright © 2011-2022 走看看