Home >php教程 >php手册 >phpmailer重复提交的有关问题

phpmailer重复提交的有关问题

WBOY
WBOYOriginal
2016-06-06 19:42:57869browse

phpmailer重复提交的问题。 http://blog.csdn.net/daydreamingboy/article/details/6299495 我要把某个页面的表单以邮件的形式用PHPMailer发送到指定邮箱,怕有人重复提交,不知道有没有这方面的专家啊? ?php if(isset($_POST['submitted'])){ require('PHPM

phpmailer重复提交的问题。
http://blog.csdn.net/daydreamingboy/article/details/6299495

我要把某个页面的表单以邮件的形式用PHPMailer发送到指定邮箱,怕有人重复提交,不知道有没有这方面的专家啊?
<?php<br />
if (isset($_POST['submitted'])) {<br />
	require('PHPMailer/class.phpmailer.php');<br />
<br />
	$mail = new PHPMailer();<br />
	//不包含表单验证<br />
	if (!empty($_POST['contact']) && !empty($_POST['subject']) &&<br />
		 !empty($_【本文来自鸿网互联 (http://www.68idc.cn)】POST['content']) && !empty($_POST['from'])) {<br />
		$address = $_POST['contact'];<br />
		$mail->Subject = $_POST['subject'];<br />
		$mail->Body = $_POST['content'];<br />
		$mail->FromName = $_POST['from'];<br />
	} else {<br />
		echo '<p><font color="red">请全部填写完整!</font></p>';<br />
		exit();<br />
	}<br />
	$mail->IsSMTP();<br />
	$mail->Host = "smtp.163.com";<br />
	$mail->SMTPAuth = true;<br />
	$mail->Username = "your_mail@163.com";<br />
	$mail->Password = "your_password";<br />
	$mail->Port = 25;<br />
	$mail->From = " your_mail@163.com";<br />
	$mail->AddAddress("$address", "my friend");<br />
<br />
	if (!$mail->Send()) {<br />
		echo "<br /><font color='red'>邮件发送失败!</font><br />";<br />
		echo "错误原因: " .$mail->ErrorInfo;<br />
		exit();<br />
	} else {<br />
		echo "<br /><font color='green'>邮件发送成功!</font><br />";<br />
	}<br />
}<br />
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"<br />
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br />
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><br />
<head><br />
	<meta http-equiv="content-type" content="text/html; charset=GBK" /><br />
	<title>使用PHPMailer发送邮件</title><br />
</head><br />
<body style="text-align: center"><br />
<br />
<form action="mail.php" method="post"><br />
	<p>联系人Email: <input name="contact" type="text" /></p><br />
	<p>发件人昵称: <input name="from" type="text" /></p><br />
	<p>主题: <input name="subject" type="text" /></p><br />
	<p>内容: <textarea name="content" rows="10" cols="25"><br />
	<p><input type="submit" value="发送" /></p><br />
	<input name="submitted" type="hidden" value="TRUE" /><br />
</form><br />
<br />
</body><br />
</html>

------解决思路----------------------
提交过的用数据库记录,再提交时,根据email地址判断是否重复。
------解决思路----------------------
session_start();<br />
$key = md5(serialize($_POST));<br />
if(empty($_SESSION['last'])) $_SESSION['last'] = $key;<br />
else if($_SESSION['last'] == $key) die('不能重复发送');<br />
//发送邮件

1、不能仅使 提交按钮 失效,因为用户可能需要发送多封邮件。何况普通的表单提交会产生新页,并不会被失效
2、不能仅从目标邮箱判断,向一个邮箱发送多封邮件是很常见的事情
3、只有在两次提交的内容完全相同时,才能视为重复
Statement:
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