diff --git a/application/admin/command/Install/fastadmin.sql b/application/admin/command/Install/fastadmin.sql
index 8678d571..1e8471ca 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', '备案号', '', '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 7cd41cbb..8c76335b 100644
--- a/application/admin/controller/general/Config.php
+++ b/application/admin/controller/general/Config.php
@@ -3,6 +3,7 @@
namespace app\admin\controller\general;
use app\common\controller\Backend;
+use app\common\controller\Email;
/**
* 系统配置
@@ -233,4 +234,19 @@ class Config extends Backend
}
}
+
+ public function emailtest()
+ {
+ $content = '
';
+
+ $email = new Email;
+ $mailArr = Array();
+ $mailArr['mTo'] = '168128864@qq.com'; //收件人
+ $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/controller/Email.php b/application/common/controller/Email.php
new file mode 100644
index 00000000..d12cf413
--- /dev/null
+++ b/application/common/controller/Email.php
@@ -0,0 +1,88 @@
+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 1f44948c..26b56c05 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/composer.json b/composer.json
index ce992757..68d66cbe 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 ed919782..4b893811 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();