DEDE织梦留言自定表单自动发送邮件到阿里云企业邮箱
更新时间:2020-11-11 08:55 已阅读: 次 | 作者:骏马网络 来源:潍坊做网站
diy.php 附件三个代码
附件代码 |
<?php
/**
*
* 自定义表单
*
* @version $Id: diy.php 1 15:38 2010年7月8日Z tianya $
* @package DedeCMS.Site
* @copyright Copyright (c) 2007 - 2010, DesDev, Inc.
* @license http://help.dedecms.com/usersguide/license.html
* @link http://www.dedecms.com
*/
require_once(dirname(__FILE__)."/../include/common.inc.php");
$diyid = isset($diyid) && is_numeric($diyid) ? $diyid : 0;
$action = isset($action) && in_array($action, array('post', 'list', 'view')) ? $action : 'post';
$id = isset($id) && is_numeric($id) ? $id : 0;
if(empty($diyid))
{
showMsg('非法操作!', 'javascript:;');
exit();
}
require_once DEDEINC.'/diyform.cls.php';
$diy = new diyform($diyid);
/*----------------------------
function Post(){ }
---------------------------*/
if($action == 'post')
{
if(empty($do))
{
$postform = $diy->getForm(true);
include DEDEROOT."/templets/plus/{$diy->postTemplate}";
exit();
}
elseif($do == 2)
{
$dede_fields = empty($dede_fields) ? '' : trim($dede_fields);
$dede_fieldshash = empty($dede_fieldshash) ? '' : trim($dede_fieldshash);
if(!empty($dede_fields))
{
if($dede_fieldshash != md5($dede_fields.$cfg_cookie_encode))
{
showMsg('数据校验不对,程序返回', '-1');
exit();
}
}
$diyform = $dsql->getOne("select * from linqu_diyforms where diyid='$diyid' ");
if(!is_array($diyform))
{
showmsg('自定义表单不存在', '-1');
exit();
}
$addvar = $addvalue = '';
if(!empty($dede_fields))
{
$fieldarr = explode(';', $dede_fields);
if(is_array($fieldarr))
{
foreach($fieldarr as $field)
{
if($field == '') continue;
$fieldinfo = explode(',', $field);
if($fieldinfo[1] == 'textdata')
{
${$fieldinfo[0]} = FilterSearch(stripslashes(${$fieldinfo[0]}));
${$fieldinfo[0]} = addslashes(${$fieldinfo[0]});
}
//时间
if($fieldinfo[0] == 'ip')
{
${$fieldinfo[0]}=GetIP();
}
if($fieldinfo[0] == 'time')
{
${$fieldinfo[0]}=date("Y-m-d H:i:s");
}
// <input type=”hidden” name=”ip” id=”ip” value=””>
// <input type=”hidden” name=”time” id=”time” value=””>
else
{
${$fieldinfo[0]} = GetFieldValue(${$fieldinfo[0]}, $fieldinfo[1],0,'add','','diy', $fieldinfo[0]);
}
$addvar .= ', `'.$fieldinfo[0].'`';
$addvalue .= ", '".${$fieldinfo[0]}."'";
}
}
}
$query = "INSERT INTO `{$diy->table}` (`id`, `ifcheck` $addvar) VALUES (NULL, 0 $addvalue); ";
//发送邮件
$mailtitle = $name."提交表单通知";
$mailbody = "称呼:{$name} 公司:{$company} 标题:{$title} 邮箱:{$email} 电话:{$tel} IP地址:{$ip} 时间:{$time} 内容:{$content}";
$headers = $cfg_adminemail;
$mailtype = 'TXT';
require_once(DEDEINC.'/mail.class.php');
$smtp = new smtp($cfg_smtp_server,$cfg_smtp_port,true,$cfg_smtp_usermail,$cfg_smtp_password);
$smtp->debug = false;
$smtp->sendmail($cfg_smtp_usermail,$cfg_webname ,$cfg_smtp_usermail, $mailtitle, $mailbody, $mailtype);
if($dsql->ExecuteNoneQuery($query))
{
$id = $dsql->GetLastID();
if($diy->public == 2)
{
//diy.php?action=view&diyid={$diy->diyid}&id=$id
$goto = "diy.php?action=list&diyid={$diy->diyid}";
$bkmsg = '发布成功,现在转向表单列表页...';
}
else
{
$goto = !empty($cfg_cmspath) ? $cfg_cmspath : '/';
$bkmsg = '发布成功,请等待管理员处理...';
}
showmsg($bkmsg, $goto);
}
}
}
/*----------------------------
function list(){ }
---------------------------*/
else if($action == 'list')
{
if(empty($diy->public))
{
showMsg('后台关闭前台浏览', 'javascript:;');
exit();
}
include_once DEDEINC.'/datalistcp.class.php';
if($diy->public == 2)
$query = "SELECT * FROM `{$diy->table}` ORDER BY id DESC";
else
$query = "SELECT * FROM `{$diy->table}` WHERE ifcheck=1 ORDER BY id DESC";
$datalist = new DataListCP();
$datalist->pageSize = 10;
$datalist->SetParameter('action', 'list');
$datalist->SetParameter('diyid', $diyid);
$datalist->SetTemplate(DEDEINC."/../templets/plus/{$diy->listTemplate}");
$datalist->SetSource($query);
$fieldlist = $diy->getFieldList();
$datalist->Display();
}
else if($action == 'view')
{
if(empty($diy->public))
{
showMsg('后台关闭前台浏览' , 'javascript:;');
exit();
}
if(empty($id))
{
showMsg('非法操作!未指定id', 'javascript:;');
exit();
}
if($diy->public == 2)
{
$query = "SELECT * FROM {$diy->table} WHERE id='$id' ";
}
else
{
$query = "SELECT * FROM {$diy->table} WHERE id='$id' AND ifcheck=1";
}
$row = $dsql->GetOne($query);
if(!is_array($row))
{
showmsg('你访问的记录不存在或未经审核', '-1');
exit();
}
$fieldlist = $diy->getFieldList();
include DEDEROOT."/templets/plus/{$diy->viewTemplate}";
}
自动获取ip地址以及自动写入当前提交时间!
这个是html代码:
自动获取ip地址以及自动写入当前提交时间!
这个是html代码:
<form class="form-horizontal" action="/plus/diy.php" enctype="multipart/form-data" method="post" onsubmit="return checkForm();">
<input type="hidden" name="action" value="post" />
<input type="hidden" name="diyid" value="288" />
<input type="hidden" name="do" value="2" />
<input name="name" id="name" type="text" style="margin-top: 10px; " class="subscribe-ipt" placeholder="Your Name">
<br>
<input name="email" id="email" type="text" style="margin-top: 10px" class="subscribe-ipt" placeholder="Your Email">
<br>
<input name="tel" id="tel" class="subscribe-ipt" style="margin-top: 10px" placeholder="Your Phone">
<br>
<input name="company" id="tel" class="subscribe-ipt" style="margin-top: 10px" placeholder="Your Company">
<br>
<input name="title" id="tel" class="subscribe-ipt" style="margin-top: 10px" placeholder="Title">
<br>
<input name="content" style='width:350px;height:50px;margin-top: 10px' id="tel" class="subscribe-ipt" placeholder="Content">
<input type='hidden' name='time' id='time' style='width:250px' class='intxt' value='' />
<input type='hidden' name='ip' id='ip' style='width:250px' class='intxt' value='' />
<input type="hidden" name="dede_fields" value="name,text;email,text;tel,text;company,text;title,text;content,multitext;time,text;ip,text" />
<input type="hidden" name="dede_fieldshash" value="64955ef59d6eeb3613ca612bf30f7e20" />
<input class="subscribe-btn" type="submit" name="submit" value="Submit">
</form>
后台邮箱配置:
完工啦~
后台邮箱配置:
完工啦~
文章引用:https://www.wfwz.net/news/245.html如需转载,请注明出处。