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 方法了

  • 相关阅读:
    动手动脑3
    AWK编程与应用
    BASH内置变量的使用
    服务器交互脚本expect
    编程对话框的界面程序
    每日打卡
    AppiumLibrary中文翻译
    Bootstrap4简单使用
    Python基础06-类与对象
    BDD模式-Python behave的简单使用
  • 原文地址:https://www.cnblogs.com/GetcharZp/p/12368293.html
Copyright © 2011-2022 走看看