PHPCMS自定义表单发送邮件中带自定义字段 直接复制下面代码替换原来phpcms\modules\formguide\index.php文件:
db = pc_base::load_model(‘sitemodel_model’);
$this->m_db = pc_base::load_model(‘sitemodel_field_model’);
$this->M = new_html_special_chars(getcache(‘formguide’, ‘commons’));
$this->siteid = intval($_GET[siteid]) ? intval($_GET[siteid]) : get_siteid();
$this->M = $this->M[$this->siteid];
}
/**
* 表单向导首页
*/
public function index() {
$siteid = $this->siteid;
$SEO = seo($this->siteid, ”, L(‘formguide_list’));
$page = max(intval($_GET[‘page’]), 1);
$r = $this->db->get_one(array(‘siteid’=>$this->siteid, ‘type’=>3, ‘disabled’=>0), ‘COUNT(`modelid`) AS sum’);
$total = $r[‘sum’];
$pages = pages($total, $page, 20);
$offset = ($page-1)*20;
$datas = $this->db->select(array(‘siteid’=>$this->siteid, ‘type’=>3, ‘disabled’=>0), ‘modelid, name, addtime’, $offset.’,20′, ‘`modelid` DESC’);
include template(‘formguide’, ‘index’);
}
/**
* 表单展示
*/
public function show() {
if (!isset($_GET[‘formid’]) || empty($_GET[‘formid’])) {
$_GET[‘action’] ? exit : showmessage(L(‘form_no_exist’), HTTP_REFERER);
}
$siteid = $_GET[‘siteid’] ? intval($_GET[‘siteid’]) : 1;
$formid = intval($_GET[‘formid’]);
$r = $this->db->get_one(array(‘modelid’=>$formid, ‘siteid’=>$siteid, ‘disabled’=>0), ‘tablename, setting’);
if (!$r) {
$_GET[‘action’] ? exit : showmessage(L(‘form_no_exist’), HTTP_REFERER);
}
$setting = string2array($r[‘setting’]);
if ($setting[‘enabletime’]) {
if ($setting[‘starttime’]>SYS_TIME || ($setting[‘endtime’]+3600*24)
$data = array();
require CACHE_MODEL_PATH.’formguide_input.class.php’;
$formguide_input = new formguide_input($formid);
$data = new_addslashes($_POST[‘info’]);
$data = new_html_special_chars($data);
$data = $formguide_input->get($data);
$data[‘userid’] = $userid;
$data[‘username’] = param::get_cookie(‘_username’);
$data[‘datetime’] = SYS_TIME;
$data[‘ip’] = ip();
$dataid = $this->m_db->insert($data, true);
if ($dataid) {
if ($setting[‘sendmail’]) {
pc_base::load_sys_func(‘mail’);
$mails = explode(‘,’, $setting[‘mails’]);
if (is_array($mails)) {
// 2012年2月29日13:22:39 增加邮件内容附带表单详情 段落1 开始
$f_info = $this->db->get_one(array(‘modelid’=>$formid, ‘siteid’=>$this->siteid));
$MailSubject = ‘用户提交表单[‘.$f_info[‘name’].’]提醒’;
$Fields = getcache(‘formguide_field_’.$formid, ‘model’);
$Fields[‘username’][‘name’] = ‘用户名’;
$Fields[‘datetime’][‘name’] = ‘提交时间’;
$Fields[‘ip’][‘name’] = ‘提交IP’;
unset($data[‘userid’], $data[‘datetime’]);
foreach($data as $k=>$v){
$MailBody .= $Fields[$k][‘name’].’ :’.$v.’
‘;
}
// 2012年2月29日13:22:39 增加邮件内容附带表单详情 段落1 结束
foreach ($mails as $m) {
// 2012年2月29日13:22:39 增加邮件内容附带表单详情 段落2 开始
sendmail($m, $MailSubject, $MailBody.$this->M[‘mailmessage’]);
// 2012年2月29日13:22:39 增加邮件内容附带表单详情 段落2 结束
}
}
}
$this->db->update(array(‘items’=>’+=1’), array(‘modelid’=>$formid, ‘siteid’=>$this->siteid));
}
showmessage(L(‘thanks’), HTTP_REFERER);
} else {
if ($setting[‘allowunreg’]==0 && !$userid && $_GET[‘action’]==’js’) {
$no_allowed = 1;
}
pc_base::load_sys_class(‘form’, ”, ”);
$f_info = $this->db->get_one(array(‘modelid’=>$formid, ‘siteid’=>$this->siteid));
extract($f_info);
$tablename = ‘form_’.$r[‘tablename’];
$this->m_db->change_table($tablename);
$ip = ip();
$where = array();
if ($userid) $where = array(‘userid’=>$userid);
else $where = array(‘ip’=>$ip);
$re = $this->m_db->get_one($where, ‘datetime’);
$setting = string2array($setting);
if (($setting[‘allowmultisubmit’]==0 && $re[‘datetime’]) || ((SYS_TIME-$re[‘datetime’])<$this->M[‘interval’]*60)) {
$_GET[‘action’] ? exit : showmessage(L(‘had_participate’), APP_PATH.’index.php?m=formguide&c=index&a=index’);
}
require CACHE_MODEL_PATH.’formguide_form.class.php’;
$formguide_form = new formguide_form($formid, $no_allowed);
$forminfos_data = $formguide_form->get();
$SEO = seo($this->siteid, L(‘formguide’), $name);
if (isset($_GET[‘action’]) && $_GET[‘action’]==’js’) {
if(!function_exists(‘ob_gzhandler’)) ob_clean();
ob_start();
}
$template = ($_GET[‘action’]==’js’) ? $js_template : $show_template;
include template(‘formguide’, $template, $default_style);
if (isset($_GET[‘action’]) && $_GET[‘action’]==’js’) {
$data=ob_get_contents();
ob_clean();
exit(format_js($data));
}
}
}
}
?>