DEDE使用AJAX无刷新提交Form表单,PHP返回结果

WBOY
Release: 2016-06-23 13:46:39
Original
947 people have browsed it

$query = "INSERT INTO `{$diy->table}` (`id`, `ifcheck` $addvar)  VALUES (NULL, 0 $addvalue); ";


引入phpmailer


添加以下代码:

/*发送邮件*/$addvalue_ary 	= explode(',', $addvalue);//因为DEDE是将所有表单数据提交过来,所以这里需要分隔一下。			$addvar_ary 	= array(									1 => '称呼',									2 => 'Email',									3 => '手机/电话',									4 => '网站',									5 => '留言内容',									);						$text = '';			foreach($addvar_ary as $key=>$value)			{				$text.=$value.': '.$addvalue_ary[$key].'<br>';			}require("class.smtp.php"); require("class.phpmailer.php"); //下载的文件必须放在该文件所在目录,把phpmailer下载后,class.phpmailer.php, class.pop3.php和 class.smtp.php放到/plus目录下$mail = new PHPMailer(); //建立邮件发送类	$mail->CharSet = "utf-8"; // 这里指定字符集!$mail->Encoding = "base64"; $mail->WordWrap = 50; // set word wrap$mail->IsHTML(true); // send as HTML$mail->IsSMTP(); // 使用SMTP方式发送$mail->Host = "smtp.163.com"; // 您的企业邮局域名,你申请发件邮箱的域名;$mail->FromName="新官网留言";$mail->SMTPAuth = true; // 启用SMTP验证功能$mail->Username = "XXXX@163.com"; // 发件邮箱用户名(请填写完整的email地址),这个邮箱是发送邮箱,phpmailer的意思就是使用一个邮箱向另一个邮箱发邮件,所以提前注册好一个邮箱$mail->Password = "XXXXXXX"; // 发件邮箱密码$mail->Port=25;$mail->From = "XXXX@163.com"; //邮件发送email地$address ="XXXX@XXX.cn";//收件人地址址$mail->AddAddress($address, "XXX");//$mail->AddAddress("XXXX@XXX.cn", "XXX");//收件人地址,可以替换成任何想要接收邮件的email信箱,格式是AddAddress("收件人email","收件人姓名")if($action == 'post') {		if($do == 2) {			$mail_title="客户留言".date('y-m-d H:i:s',time());	$mail->Subject = $mail_title; //邮件标题	$mail->Body = $text; //邮件内容,$name,$phone..等是你取的用户前端提交过来的值,如果不想取数的话,就写个提示信息,如,网站有新订单了,请登录网站及时处理。	//showMsg('发送之前', 'javascript:;');		if(!$mail->send())		{		//echo "Fail to send.";		showMsg('发送失败', 'javascript:;');		//showmsg('发送失败');		exit;		}		//showMsg('发送成功', 'javascript:;');		//echo "邮件发送成功"; //dede可以用showmsg('发送成功');来测试是否发送成功	}}/*End 发送邮件*/																							        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 =  '-1';                $bkmsg = '邮件已经自动发送到SPARK工作人员,请等待联系您!';            }			echo "OK";            //showmsg($bkmsg, $goto);        }    }}
Copy after login



JS代码:

var dataString = 'iname='+ $("#name").val() + '&email=' + $("#email").val() + '&tel=' + $("#tel").val()+ '&website=' + $("#website").val()+ '&action=post'+ '&diyid=1&do=2&dede_fields=iname,text;email,text;tel,text;website,text;content,text&dede_fieldshash=1f6d061a5dd65989abfd887'; $.ajax({ 	type: "POST", 	url: "/plus/diy.php", 	data: dataString, 	success: function(data) { 		if(data=="OK"){				   		//关闭遮罩						$("#submitmask").fadeOut(500);						alert("提交成功!");				   }else{					   		$("#submitmask").fadeOut(500);							alert("出错了!请使用其他方式联系我们!");					   }	} }); return false;
Copy after login




source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template