第一次在这里发帖。我在CMS网站上有一个php联系表单,它向我发送了重复的电子邮件。问题是间歇性的。有时会发送两份副本,有时会发送多达8份。有时候它能正常工作。从表单中删除一些字段后,问题就开始了。
表单提交到一个单独的页面,该页面将电子邮件发送给3个收件人。此页面还可用作感谢页面,显示用户提交的信息。 “感谢您与我们联系,已收到以下信息”。
嵌入是expresionengine代码。谢谢你的帮助!!!
以下是表格:
<form id="Form1" name="Form1" method="post" action="http://myprocessingpage.com">
<label for="fname">Name:</label> <input type="text" size="42" id="fname" name="fname"><br>
<label for="email">Email Address:</label> <input size="42" type="text" id="email" name="email"><br>
<label for="telephone">Telephone:</label> <input size="42" type="text" id="telephone" name="telephone"><br>
<br>
<div style="float: left; margin-right: 20px; margin-bottom: 30px;">
<label>How did you hear about us?</label> <br>
<input type="hidden" id="arrayfix" name="how[]" value="">
<input type="checkbox" id="website" name="how[]" value="website"> Website<br>
<input type="checkbox" id="referral" name="how[]" value="referral"> Referral<br>
<input type="checkbox" id="tradeshow" name="how[]" value="tradeshow"> Tradeshow<br>
</div>
<div style="float: left; margin-bottom: 30px;">
<label >Shelter Type:</label><br>
<input type="hidden" id="arrayfix2" name="type[]" value="">
<input type="checkbox" id="safe4x6" name="type[]" value="Safe_Room_4X6"> 4'X6' Shelter<br>
<input type="checkbox" id="safe4x8" name="type[]" value="Safe_Room_4X8"> 4'X8' Shelter<br>
<input type="checkbox" id="custom" name="type[]" value="Custom_Size_Safe_Room"> Custom Size Shelter<br>
</div>
<div style="clear: both;"></div>
<label for="question"> Questions or Comments:</label><br> <textarea rows="7" maxlength="500" name="question" id="question" cols="50"></textarea><br>
<br>
<input type="submit" class="btnimage" id="submit" name="submit" value="">
</form>
这是处理页面(http://myprocessingpage.com):
<?php
if (isset($_POST['fname']))
{
?>
<!DOCTYPE html>
<head>
<title>Thank you for contacting us!</title>
{embed="page/headtags"}
</head>
<body>
{embed="page/header"}
{embed="page/drop"}
<div id="contentbg">
<div id="content">
<?php
$name = $_POST['fname'];
$telephone = $_POST['telephone'];
$email = $_POST['email'];
$question = $_POST['question'];
$howarray = $_POST['how'];
$howimplode = implode("\n", $howarray);
$how = str_replace("_", " ", "$howimplode");
$typearray = $_POST['type'];
$typeimplode = implode("\n", $typearray);
$type = str_replace("_", " ", "$typeimplode");
//sent to us
$to = "mail1@mail.com, mail2@mail.com, mail3@mail.com";
$subject = "Info Request";
$message = "INFO REQUEST:\n\nName: $name\n\nEmail: $email\n\nTelephone: $telephone\n\nHow they heard about us:\n$how\n\nShelter type:\n$type\n\nQuestions or Comments:\n$question";
$from = "info@mysite.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
?>
<div id="form">
<p style="margin-top: 0px; margin-bottom: 40px; color: green; font-weight: bold;">Thank you for contacting us! The following information has been received:</p>
<div style="margin-left: 30px;">
<?php
echo "<p><b>Name:</b> ".$name."</p>";
echo "<p><b>Email:</b> ".$email."</p>";
echo "<p><b>Telephone:</b> ".$telephone."</p>";
$thankshowimplode = implode("</br>", $howarray);
$thankshow = str_replace("_", " ", "$thankshowimplode");
$thankstypeimplode = implode("</br>", $typearray);
$thankstype = str_replace("_", " ", "$thankstypeimplode");
echo "<p><b>How you heard about us:</b></br> ".$thankshow."</p>";
echo "<p><b>Type of shelter(s):</b></br> ".$thankstype."</p>";
echo "<p style='word-wrap:break-word;'><b>Questions or Comments:</b> ".$question."</p>";
?>
</div>
</div>
</div>
{embed="page/footer"}
</body>
</html>
<?php
}
else
{
?>
<script type="text/javascript">
window.location = 'http://mycontactpage.com';
</script>
<?php
}
?>
答案 0 :(得分:0)
如果有人双击(或点击8次)您的提交按钮,您的脚本可能会多次运行。尝试在点击时禁用提交按钮(使用Javascript)。
另一个可能不必要的解决方案是锁定表单脚本(例如使用信号量),使用提供的信息创建数据库条目,然后检查您是否最近发送了相同的信息(例如,在最近的五个内分钟),如果你有,请不要再发送。
我确定Javscript禁用功能就足够了:)
或者,如果你想知道真正发生了什么,你可以创建一个日志文件,记录“在[timestamp]”发送[可能告诉这些帖子的一些不同的数据]。如果你看到其中的几个,使用相同的[distinct info]条目并且真正关闭时间戳,那么你的问题就是多次点击提交按钮。