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>
<div class="aritcle_card">
<a class="aritcle_card_img" href="/xiazai/code/11161">
<img src="https://img.php.cn/upload/webcode/000/000/004/176517540225235.jpg" alt="Ztoy网络商铺多用户版">
</a>
<div class="aritcle_card_info">
<a href="/xiazai/code/11161">Ztoy网络商铺多用户版</a>
<p>在原版的基础上做了一下修正:增加1st在线支付功能与论坛用户数据结合,vip也可与论坛相关,增加互动性vip会员的全面修正评论没有提交正文的问题特价商品的调用连接问题删掉了2个木马文件去掉了一个后门补了SQL注入补了一个过滤漏洞浮动价不能删除的问题不能够搜索问题收藏时放入购物车时出错点放入购物车弹出2个窗口修正定单不能删除问题VIP出错问题主题添加问题商家注册页导航连接问题添加了导航FLASH源文</p>
<div class="">
<img src="/static/images/card_xiazai.png" alt="Ztoy网络商铺多用户版">
<span>0</span>
</div>
</div>
<a href="/xiazai/code/11161" class="aritcle_card_btn">
<span>查看详情</span>
<img src="/static/images/cardxiayige-3.png" alt="Ztoy网络商铺多用户版">
</a>
</div>
<br />
<p>内容: <textarea name="content" rows="10" cols="25"><br />
<p><input type="submit" value="发送" /></p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)</a>”;</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 />
//发送邮件
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号