phpmailer重复提交的问题。 http://blog.csdn.net/daydreamingboy/article/details/6299495 我要把某个页面的表单以邮件的形式用PHPMailer发送到指定邮箱,怕有人重复提交,不知道有没有这方面的专家啊? ?php if(isset($_POST['submitted'])){ require('PHPM
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>
session_start();<br /> $key = md5(serialize($_POST));<br /> if(empty($_SESSION['last'])) $_SESSION['last'] = $key;<br /> else if($_SESSION['last'] == $key) die('不能重复发送');<br /> //发送邮件