diff --git a/application/admin/command/Install/fastadmin.sql b/application/admin/command/Install/fastadmin.sql index 8678d5710aa19e0bead6682f53c0d1d37433ce5a..12469c9596f8b73d664e748d7f1f13d7d00c5e4b 100755 --- a/application/admin/command/Install/fastadmin.sql +++ b/application/admin/command/Install/fastadmin.sql @@ -227,7 +227,7 @@ CREATE TABLE `fa_config` ( -- Records of `fa_config` -- ---------------------------- BEGIN; -INSERT INTO `fa_config` VALUES ('1', 'name', 'basic', '站点名称', '请填写站点名称', 'string', 'FastAdmin', '', 'required', ''), ('2', 'beian', 'basic', '备案号', '', 'string', '', '', '', ''), ('3', 'cdnurl', 'basic', 'CDN地址', '如果使用CDN云储存请配置该值', 'string', '', '', '', ''), ('4', 'version', 'basic', '版本号', '如果静态资源有变动请重新配置该值', 'string', '1.0.1', '', 'required', ''), ('5', 'timezone', 'basic', '时区', '', 'string', 'Asia/Shanghai', '', 'required', ''), ('6', 'forbiddenip', 'basic', '禁止访问IP', '一行一条记录', 'text', '', '', '', ''), ('7', 'languages', 'basic', '模块语言', '', 'array', '{\"backend\":\"zh-cn\",\"frontend\":\"zh-cn\"}', '', 'required', ''), ('8', 'fixedpage', 'basic', '后台默认页', '请尽量输入左侧菜单栏存在的链接', 'string', 'dashboard', '', 'required', ''), ('9', 'categorytype', 'dictionary', '分类类型', '', 'array', '{\"default\":\"默认\",\"page\":\"单页\",\"article\":\"文章\",\"test\":\"测试\"}', '', '', ''), ('10', 'configgroup', 'dictionary', '配置分组', '', 'array', '{\"basic\":\"基础配置\",\"email\":\"邮件配置\",\"dictionary\":\"字典配置\",\"user\":\"会员配置\",\"example\":\"示例分组\"}', '', '', ''); +INSERT INTO `fa_config` VALUES ('1', 'name', 'basic', '站点名称', '请填写站点名称', 'string', 'FastAdmin', '', 'required', ''), ('2', 'beian', 'basic', '备案号', '粤ICP备15054802号-4', 'string', '', '', '', ''), ('3', 'cdnurl', 'basic', 'CDN地址', '如果使用CDN云储存请配置该值', 'string', '', '', '', ''), ('4', 'version', 'basic', '版本号', '如果静态资源有变动请重新配置该值', 'string', '1.0.1', '', 'required', ''), ('5', 'timezone', 'basic', '时区', '', 'string', 'Asia/Shanghai', '', 'required', ''), ('6', 'forbiddenip', 'basic', '禁止访问IP', '一行一条记录', 'text', '', '', '', ''), ('7', 'languages', 'basic', '模块语言', '', 'array', '{\"backend\":\"zh-cn\",\"frontend\":\"zh-cn\"}', '', 'required', ''), ('8', 'fixedpage', 'basic', '后台默认页', '请尽量输入左侧菜单栏存在的链接', 'string', 'dashboard', '', 'required', ''), ('9', 'categorytype', 'dictionary', '分类类型', '', 'array', '{\"default\":\"默认\",\"page\":\"单页\",\"article\":\"文章\",\"test\":\"测试\"}', '', '', ''), ('10', 'configgroup', 'dictionary', '配置分组', '', 'array', '{\"basic\":\"基础配置\",\"email\":\"邮件配置\",\"dictionary\":\"字典配置\",\"user\":\"会员配置\",\"example\":\"示例分组\"}', '', '', ''),('11','mail_type','email','邮件发送方式','选择邮件发送方式','select','1','[\"请选择\",\"SMTP\",\"mail()函数\"]','',''),('12','mail_smtp_host','email','SMTP[服务器]','错误的配置发送邮件会导致服务器超时','string','smtp.qq.com','','',''),('13','mail_smtp_port','email','SMTP[端口]','(不加密默认25,SSL默认465,TLS默认587)','string','465','','',''),('14','mail_smtp_user','email','SMTP[用户名]','(填写完整用户名)','string','10000','','',''),('15','mail_smtp_pass','email','SMTP[密码]','(填写您的密码)','string','password','','',''),('16','mail_verify_type','email','SMTP验证方式','(SMTP验证方式[推荐SSL])','select','2','[\"无\",\"TLS\",\"SSL\"]','',''),('17','mail_from','email','发件人邮箱','','string','10000@qq.com','','',''); COMMIT; -- ---------------------------- diff --git a/application/admin/controller/general/Config.php b/application/admin/controller/general/Config.php index 7cd41cbb10c9ff4e4c28fc0e3274a8591a43dafa..618bb3a64d8812cfc22eb904dfd328a44b1ab861 100644 --- a/application/admin/controller/general/Config.php +++ b/application/admin/controller/general/Config.php @@ -1,7 +1,9 @@ 这是一封测试邮件,用于测试邮件配置是否正常!'; + + $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'=>'操作完成']); + } } diff --git a/application/common/library/Email.php b/application/common/library/Email.php new file mode 100644 index 0000000000000000000000000000000000000000..e60ddadddda355378feb32995e140e2e0e02a705 --- /dev/null +++ b/application/common/library/Email.php @@ -0,0 +1,86 @@ +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; + } + } +} diff --git a/application/extra/site.php b/application/extra/site.php index 1f44948c35bfe96da4b23da47b0167e6af17ebc3..26b56c0581fa9e98e3c770fd678515e6479e5bec 100644 --- a/application/extra/site.php +++ b/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', ); \ No newline at end of file diff --git a/application/index/view/layout/bootstrap.html b/application/index/view/layout/bootstrap.html index 71509bb0a86b9a771b7bae7b094f47045e66c06a..f56dbb6c4fa2b11500b28df4f4e0ad3858555e8a 100644 --- a/application/index/view/layout/bootstrap.html +++ b/application/index/view/layout/bootstrap.html @@ -94,7 +94,7 @@

- 粤ICP备15054802号-4 + {$site.beian}

diff --git a/composer.json b/composer.json index ce992757391635312765a818b6ca5ba7810706c2..68d66cbe01e6ab189c0c56e6c41b09512210881f 100755 --- a/composer.json +++ b/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" diff --git a/public/assets/js/backend/general/config.js b/public/assets/js/backend/general/config.js index ed9197822305d0e7e99b9aaf21dfd8495389ff4f..4b893811e4f2d8701a88b6f692a5a3788c0c2dd8 100644 --- a/public/assets/js/backend/general/config.js +++ b/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 = '向发件人发送测试邮件' + $('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(); diff --git a/public/assets/js/backend/general/configvalue.js b/public/assets/js/backend/general/configvalue.js index 00d36445b69c22a8bca257ed55a359f4553179aa..960a487dd08855223a9295b53a73c4a379fce5f3 100755 --- a/public/assets/js/backend/general/configvalue.js +++ b/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({