Browse Source

Merge pull request !11 from gaoyi/master

gaoyi 7 years ago
parent
commit
937ebe6dca

File diff suppressed because it is too large
+ 1 - 1
application/admin/command/Install/fastadmin.sql


+ 19 - 1
application/admin/controller/general/Config.php

@@ -1,7 +1,9 @@
 <?php
 
 namespace app\admin\controller\general;
-
+ 
+use think\Config as tpConfig;
+use app\common\library\Email;
 use app\common\controller\Backend;
 
 /**
@@ -233,4 +235,20 @@ class Config extends Backend
         }
     }
 
+
+    public function emailtest()
+    {
+        $content = '<table style="width: 99.8%; "><tbody><tr><td id="QQMAILSTATIONERY" style="background:url(https://rescdn.qqmail.com/zh_CN/htmledition/images/xinzhi/bg/a_07.jpg) repeat-x #e4ebf5; min-height:550px; padding: 100px 55px 200px;">这是一封测试邮件,用于测试邮件配置是否正常!</td></tr></tbody></table>';
+
+        $site = tpConfig::get("site");
+        $email = new Email;
+        $mailArr = Array();
+        $mailArr['mTo'] = $site['mail_from'];       //收件人
+        $mailArr['subject'] = '这是一封测试邮件';    //邮件主题
+        $mailArr['content'] = $content;             //邮件内容(html)
+        $mailArr['fromNic'] = 'Fastadmin系统邮件';   //发件人昵称[可省略]
+        $mailArr['toNic'] = '亲爱的用户';            //收件人昵称[可省略]貌似无效
+        $data = $email->sendMail($mailArr['mTo'],$mailArr['subject'],$mailArr['content'],$mailArr['fromNic'],$mailArr['toNic']);
+        return json(['data'=>$data,'code'=>200,'message'=>'操作完成']);
+    }
 }

+ 86 - 0
application/common/library/Email.php

@@ -0,0 +1,86 @@
+<?php
+
+namespace app\common\library;
+
+use think\Config;
+
+class Email
+{
+    /**
+     * 发送邮件
+     * @param string $mTo 收件人
+     * @param string $subject 邮件主题
+     * @param string $content 邮件内容(html)
+     * @param string $fromNic 发件人昵称
+     * @param string $toNic 收件人昵称
+     */
+    public function sendMail($mTo='',$subject='',$content='',$fromNic='',$toNic='')
+    {
+        $site = Config::get("site");
+        $re = Vendor('phpmailer.phpmailer.PHPMailerAutoload');
+
+        $mail = new \PHPMailer ();
+
+        //$mail->SMTPDebug = 3;                               // Enable verbose debug output
+        $mail->isSMTP();                                      //smtp需要鉴权 这个必须是true
+        $mail->Host = $site['mail_smtp_host'];                //SMTP服务器地址
+        $mail->SMTPAuth = true;                               // Enable SMTP authentication
+        $mail->Username = $site['mail_smtp_user'];            // SMTP 用戶名
+        $mail->Password = $site['mail_smtp_pass'];            // SMTP 密碼
+        switch ($site['mail_verify_type'])                    // Enable TLS encryption, `ssl` also accepted
+        {
+        case 1:
+          $mail->SMTPSecure = 'tls';
+          break;
+        case 2:
+          $mail->SMTPSecure = 'ssl';
+          break;
+        default:
+          $mail->SMTPSecure = '';
+        }
+        $mail->Port = $site['mail_smtp_port'];                                      // 设置ssl连接smtp服务器的远程服务器端口号
+        $mail->setFrom($site['mail_from'], $fromNic);                               // [发件人],[昵称(可选)]
+        $mail->addAddress($mTo, $toNic);                                            // [收件人],[昵称(可选)]
+        //$mail->addReplyTo('xxxxxx@qq.com', 'Information');                        // 回复地址(可选)
+        //$mail->addCC('xxxxxx@qq.com');                                            //好像是密送
+        //$mail->addBCC('xxxxxx@qq.com');                                           //好像是密送B
+        // $mail->addAttachment('/var/tmp/file.tar.gz');                            // 添加附件
+        // $mail->addAttachment('/tmp/image.jpg', 'new.jpg');                       // 附件名选项
+        $mail->isHTML(true);                                                        //邮件正文是否为html编码
+        $mail->Subject = $subject;                                                  //添加邮件主题
+        $mail->Body    = $content;                                                  //邮件正文
+        //$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';//附加信息,可以省略
+
+        switch ($site['mail_type'])
+        {
+        case 1:
+            if(!$mail->send()) {//这里如果提交错误的smpt配置PHPmailer会卡住暂时不清楚为什么
+                $sendResult['text'] = $mail->ErrorInfo;
+                $sendResult['data'] = false;
+                return $sendResult;
+            } else {
+                $sendResult['text'] ='smtp发送成功';
+                $sendResult['data'] = true;
+                return $sendResult;
+            }
+            break;
+        case 2://使用mail方法发送邮件
+            $headers  = 'MIME-Version: 1.0' . "\r\n";
+            $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
+            $headers .= 'To: '.$toNic.' <'.$mTo.'>' . "\r\n";//收件人
+            $headers .= 'From: '.$fromNic.' <'.$site['mail_from'].'>' . "\r\n";//发件人
+            $sendResult['data'] = mail($mTo, $subject, $content, $headers);
+            if ($sendResult['data']) {
+                $sendResult['text'] ='mail函数发送成功';
+            }else{
+                $sendResult['text'] ='mail函数发送失败';
+            }
+            return $sendResult;
+            break;
+        default:
+            $sendResult['data'] = false;
+            $sendResult['text'] ='已关闭邮件发送';
+            return $sendResult;
+        }
+    }
+}

+ 8 - 1
application/extra/site.php

@@ -2,7 +2,7 @@
 
 return array (
   'name' => 'FastAdmin',
-  'beian' => '',
+  'beian' => '粤ICP备15054802号-4',
   'cdnurl' => '',
   'version' => '1.0.1',
   'timezone' => 'Asia/Shanghai',
@@ -28,4 +28,11 @@ return array (
     'user' => '会员配置',
     'example' => '示例分组',
   ),
+  'mail_type' => '1',
+  'mail_smtp_host' => 'smtp.qq.com',
+  'mail_smtp_port' => '465',
+  'mail_smtp_user' => '10000',
+  'mail_smtp_pass' => 'password',
+  'mail_verify_type' => '2',
+  'mail_from' => '10000@qq.com',
 );

+ 1 - 1
application/index/view/layout/bootstrap.html

@@ -94,7 +94,7 @@
 
                         <div class="pull-left">
                             <p>
-                                <span class="text-muted"><a href="http://www.miitbeian.gov.cn/" target="_blank">粤ICP备15054802号-4</a></span>
+                                <span class="text-muted"><a href="http://www.miitbeian.gov.cn/" target="_blank">{$site.beian}</a></span>
                             </p>
                             <span class="small"></span>
                             <p>

+ 2 - 1
composer.json

@@ -20,7 +20,8 @@
         "overtrue/wechat": "~3.1",
         "endroid/qrcode": "^1.9",
         "topthink/think-captcha": "^1.0",
-        "mtdowling/cron-expression": "^1.2"
+        "mtdowling/cron-expression": "^1.2",
+        "phpmailer/phpmailer": "^5.2"
     },
     "config": {
         "preferred-install": "dist"

+ 13 - 0
public/assets/js/backend/general/config.js

@@ -76,6 +76,19 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
             $(document).on("change", "form#add-form select[name='row[type]']", function (e) {
                 $("#add-content-container").toggleClass("hide", ['select', 'selects', 'checkbox', 'radio'].indexOf($(this).val()) > -1 ? false : true);
             });
+
+            //添加向发件人发送测试邮件按钮和方法
+            testMail = '<a class="btn btn-info testmail">向发件人发送测试邮件</a>'
+            $('input[name="row[mail_from]"]').parent().next().append(testMail);
+            $(document).on("click", ".testmail",function(){
+                $.get("/admin/general.config/emailtest", function(result){
+                    if (result.data.data) {
+                        Toastr.success(result.data.text)
+                    }else{
+                        Toastr.warning(result.data.text)
+                    }
+                });
+            })
         },
         add: function () {
             Controller.api.bindevent();

+ 1 - 1
public/assets/js/backend/general/configvalue.js

@@ -35,7 +35,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
             // 为表格绑定事件
             Table.api.bindevent(table);
 
-            // 清缓存
+            // 清缓存
             $(document).on("click", ".btn-clear-cache", function (e) {
                 Backend.api.layer.confirm(__("Are you sure you want to clear cache?"), function () {
                     Backend.api.ajax({