2、打开网站根目录下的plus文件夹,里面有个diy.php文件(表单提交后处理文件),打开它,在85行上下有如下代码: $query = "INSERT INTO `{$diy->table}` (`id`, `ifcheck` $addvar) VALUES (NULL, 0 $addvalue); ";这个代码就是将表单数据写入数据库,那么我们就在他下方,加上发送邮件的功能(最下方有我改得diy.php代码 UTF8的! 直接复制放进去! 改下第88行的name):
- $mailtitle = "用户订单信息";//邮件标题
- $mailbody = "称呼:{$name}rn邮箱:{$email}rn所在城市:{$city}rn国家:{$guojia}rn电话:{$tel}rn类别:{$qudao}";//$name中name是该input元素的id号
- $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服务
- $smtp->debug = false;//不起用调试
- $smtp->sendmail($cfg_smtp_usermail,$cfg_webname ,$cfg_smtp_usermail, $mailtitle, $mailbody, $mailtype);//发送邮件
下面是我个人的测试diy.php代码
第八十八行非常重要! 你要把你表单里面的name全部放进去! 内容才可以!
- <?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(emptyempty($diyid))
- {
- showMsg('非法操作!', 'javascript:;');
- exit();
- }
- require_once DEDEINC.'/diyform.cls.php';
- $diy = new diyform($diyid);
- /*----------------------------
- function Post(){ }
- ---------------------------*/
- if($action == 'post')
- {
- if(emptyempty($do))
- {
- $postform = $diy->getForm(true);
- include DEDEROOT."/templets/plus/{$diy->postTemplate}";
- exit();
- }
- elseif($do == 2)
- {
- $dede_fields = emptyempty($dede_fields) ? '' : trim($dede_fields);
- $dede_fieldshash = emptyempty($dede_fieldshash) ? '' : trim($dede_fieldshash);
- if(!emptyempty($dede_fields))
- {
- if($dede_fieldshash != md5($dede_fields.$cfg_cookie_encode))
- {
- showMsg('数据校验不对,程序返回', '-1');
- exit();
- }
- }
- $diyform = $dsql->getOne("select * from dede_diyforms where diyid='$diyid' ");
- if(!is_array($diyform))
- {
- showmsg('自定义表单不存在', '-1');
- exit();
- }
- $addvar = $addvalue = '';
- if(!emptyempty($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]});
- }
- 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 = "用户订单信息";//邮件标题
- $mailbody = "称呼:{$name}rn邮箱:{$email}rn电话:{$tele}rn手机:{$sj}rn地址:{$dz}rn说明:{$sm}";//$name中name是该input元素的id号
- $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服务
- $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 = !emptyempty($cfg_cmspath) ? $cfg_cmspath : '/';
- $bkmsg = '发布成功,请等待管理员处理...';
- }
- showmsg(未经允许不得转载:Str Tom工作室 » 织梦如何自定义表单客户提交后如何发到自己邮箱?