request->param(); $locationHref = getFromPage(); if ($this->request->isPost()) { $id = $param["id"]; if (empty($id)) { $content = ""; $type = "html"; return Response::create($content, $type, 0); } else { $formList = FormList::find($id); if ($formList['verify'] == 1) { //开启 if (empty($param['vercode'])) { $content = ""; $type = "html"; return Response::create($content, $type, 0); } if (array_key_exists("vercode", $param) && !captcha_check($param['vercode'])) { //验证码 $respContent = ""; $type = "html"; return Response::create($respContent, $type, 0); } } $key = getAccessIP() . "_" . $id; //用于记录时间 $commit_type = $formList["commit_type"]; if ($commit_type == 1) { //同IP在5分钟内,只许提交1次,可免避恶意多次提交。 $timestamp1 = saveToCache($key); if ($timestamp1 != null) { $timestampArr = time_diff($timestamp1, time()); $hours = $timestampArr["hours"]; //小时 $minutes = $timestampArr["minutes"]; //分钟 if ($hours <= 0 && $minutes < $this->limitTime) { $content = ""; $type = "html"; return Response::create($content, $type, 0); } } } if (!$formList) { $content = ""; $type = "html"; return Response::create($content, $type, 0); } unset($param["id"]); //移出表单id unset($param["vercode"]); //移出表单验证码 $formFields = FormField::where(["form_list_id" => $id, "is_require" => 1])->select()->toArray(); $formData = []; if (sizeof($formFields) > 0) { $noExistParam = []; //没有必填字段 $paramNull = []; //必填字段内容为空 foreach ($formFields as $formField) { $isExist = false; if (key_exists($formField["name"], $param)) { $isExist = true; } if ($isExist) { //存在判断值是否为空 if (empty($param[$formField['name']]) || $param[$formField['name']] == null) { array_push($paramNull, $formField['name']); } else { //不为空的时候处理一下内容 $fieldVal = $param[$formField['name']]; $fieldVal = form_replace($fieldVal); $param[$formField['name']] = $fieldVal; array_push($formData, ['title' => $formField['title'], 'value' => $fieldVal]); } } else { array_push($noExistParam, $formField['name']); } } if (sizeof($noExistParam) > 0) { $content = ""; $type = "html"; return Response::create($content, $type, 0); } if (sizeof($paramNull) > 0) { $content = ""; $type = "html"; return Response::create($content, $type, 0); } } $r = Db::table($formList['table_name'])->strict(false)->insert($param); if ($r) { if ($formList['email_setting'] == 1) { //开启邮件通知 $this->sendMail($formList['template_id'], $formData); } saveToCache($key, time()); //记录一下时间 $content = ""; $type = "html"; return Response::create($content, $type, 200); } else { $content = ""; $type = "html"; return Response::create($content, $type, 0); } } } $content = ""; $type = "html"; return Response::create($content, $type, 0); } /** * 生成验证码 */ public function verify() { return Captcha::create(); } /** * 发送邮件 */ private function sendMail($template_id, $formData) { $pmcArr = Db::name('plugin_mail_config')->select(); if (sizeof($pmcArr) > 0) { $pluginMailConfig = $pmcArr[0]; $pmt = Db::name('plugin_mail_template')->find($template_id); $title = $pmt['title']; $to = $pluginMailConfig['test_account']; $contents = [" 邮件通知

尊敬的FoxCMS用户

这是一封来自您网站的通知邮件!

您网站收到新的表单信息,可登录网后后台“应用-自定义表单”中查看。

以下是消息内容


"]; $template_content = $pmt['content']; foreach ($formData as $key => $fd) { $tc = str_replace("__TITLE__", $fd['title'], $template_content); $tc = str_replace("__CONTENT__", $fd['value'], $tc); array_push($contents, $tc); } array_push($contents, '
'); $mail = new PHPMailer(); $mail->SMTPDebug = 0; $mail->isSMTP(); $mail->SMTPAuth = true; $mail->Host = trim($pluginMailConfig['smtp_url']); $mail->SMTPSecure = 'ssl'; $mail->Port = $pluginMailConfig['smtp_port']; $mail->Hostname = ''; $mail->CharSet = 'UTF-8'; $mail->FromName = 'FoxCMS网站消息'; $mail->Username = trim($pluginMailConfig['send_account']); $mail->Password = trim($pluginMailConfig['auth_code']); $mail->From = trim($pluginMailConfig['send_account']); $mail->isHTML(true); $mail->addAddress($to, ''); $mail->Subject = $title; $mail->Body = implode("", $contents); try { $mail->send(); } catch (\Exception $e) { } } } }