0

第一次在这里发帖。我在一个 CMS 网站上有一个 php 联系表,它正在向我发送重复的电子邮件。问题是间歇性的。有时它发送两份,有时它发送多达八份。有时它可以正常工作。从表单中删除一些字段后,问题就开始了。

表单提交到一个单独的页面,该页面将电子邮件发送给 3 个收件人。此页面还用作显示用户提交的信息的感谢页面。“感谢您与我们联系,已收到以下信息”。

嵌入是表达式引擎代码。谢谢你的帮助!!!

这是表格:

<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
}
?>
4

1 回答 1

0

如果有人双击(或单击 8 次)您的提交按钮,您的脚本可能会运行不止一次。尝试禁用单击时的提交按钮(使用 Javascript)。

另一个可能不必要的解决方案是锁定您的表单脚本(例如使用信号量),使用提供的信息创建一个数据库条目,然后检查您最近是否发送了相同的信息(例如在过去五分钟内),如果有,请不要再次发送。

我确信 Javscript 禁用功能就足够了 :)

或者,如果您想了解真正发生了什么,您可以创建一个日志文件,记录“在 [timestamp] 发送的 [一些可能区分这些帖子的不同数据]”。如果您看到其中的几个,具有相同的 [distinct info] 条目并且真正关闭时间戳,那么您的问题是多次单击提交按钮。

于 2014-05-07T01:32:58.240 回答