我已经设置了一个PHP表单,它利用AJAX和jQuery来验证和提交表单。一切似乎都很好,但无论出于什么原因,我的客户(网站所有者)收到多个副本的每一封邮件。每条消息的拷贝数从1份到10份不等,没有特定的模式。
在我所做的所有测试中,我个人只在我的商业电子邮件地址,以及在另一个gmail帐户上收到一份信息。然而,客户端,其域名注册主机,他们的电子邮件帐户,收到任何地方多达10份副本一次。
我们是托管网站,为此,我们的服务器正在处理每次发送消息时的表单。我已经检查了我们的服务器邮件日志,并且可以确认它只发送了一次。
快把我逼疯了。我们并没有花上几个小时来想办法解决这个问题,而且在这个问题上浪费了每一分钱。
我会给你我的代码和现场网站。希望有人能帮我!!
首先,这里是一个网站,您可以在这里看到正在运行的表单:http://www.energywisesolutions.ca/
您可以单击任何“图书家庭评估”链接/按钮,以查看该表单幻灯片打开。
这是我用于表单验证的脚本:http://www.position-relative.net/creation/formValidator/
下面是我的表单验证检查,然后是表单发送脚本:
$(document).ready(function() {
/* ASSESSMENT FORM
----------------------------------------------------------------*/
// Form Validation
$("#contact-form .send").click(function(){
$("#contact-form").validationEngine('attach', {
onValidationComplete: function(form, status){
if(status==true){
$("#contact-form .send").clone().insertAfter($(this)).attr("disabled","true");
$("#contact-form .send").hide();
_gaq.push(['_trackPageview', '/online-thankyou']);
$.post('/themes/energywise/mail-form/process.php', $("#contact-form").serialize(), function(data) {
// Add Thank You Message
$('#thank-you-message').html(data);
// Create IFRAME to page with Adwords Tracking Script
function ppcconversion() {
var iframe = document.createElement('iframe');
iframe.style.width = '0px';
iframe.style.height = '0px';
document.body.appendChild(iframe);
iframe.src = 'http://www.energywisesolutions.ca/themes/energywise/mail-form/conversion-script.php';
};
ppcconversion();
});
}
}
});
});
});下面是我的表单处理脚本:
$toAdmin='info@energywisesolutions.ca';
$fromAdmin='info@energywisesolutions.ca';
$toVisitor=stripslashes($_POST['email']);
$name=stripslashes($_POST['full_name']);
$city=stripslashes($_POST['city']);
$phone=stripslashes($_POST['phone']);
$comments=stripslashes($_POST['comments']);
/* TO ADMIN */
$headersToAdmin = "From: " .$toVisitor. "\r\n";
$headersToAdmin .= "Content-type: text/html; charset=iso-8859-1\r\n";
$subjectToAdmin='Energywise Website Lead - Home Assessment Form';
$messageToAdmin = '<html><body>';
$messageToAdmin .= '<img src="http://www.energywisesolutions.ca/energy-rebates/form1.jpg" alt="Home Assessment Form" />';
$messageToAdmin .= '<p>A website visitor has filled out thea Home Assessment Form. Here is their information and the comments they provided:</p>';
$messageToAdmin .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$messageToAdmin .= "<tr style='background: #eee;'><td><strong>Sent From:</strong> </td><td>ENERGYWISE WEBSITE</td></tr>";
$messageToAdmin .= "<tr><td><strong>Name:</strong> </td><td>" .$name. "</td></tr>";
$messageToAdmin .= "<tr><td><strong>City:</strong> </td><td>" .$city. "</td></tr>";
$messageToAdmin .= "<tr><td><strong>Email:</strong> </td><td>" .$toVisitor. "</td></tr>";
$messageToAdmin .= "<tr><td><strong>Phone:</strong> </td><td>" .$phone. "</td></tr>";
$messageToAdmin .= "<tr><td><strong>Comments:</strong> </td><td>" .$comments. "</td></tr>";
$messageToAdmin .= "</table>";
$messageToAdmin .= "</body></html>";
/* TO VISITOR */
$headersToVisitor = "From: " .$fromAdmin. "\r\n";
$headersToVisitor .= "Content-type: text/html; charset=iso-8859-1\r\n";
$subjectToVisitor='Thank you for Contacting Energywise Solutions';
$messageToVisitor = '<html><body>';
$messageToVisitor .= '<img src="http://www.energywisesolutions.ca/energy-rebates/form1.jpg" alt="Home Assessment Form" />';
$messageToVisitor .= '<p>Hello,</p>
<p>Thank you for contacting Energywise Solutions. We have received your message and will get in touch with you shortly.</p>
<p>Your information has been attached below:</p>';
$messageToVisitor .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$messageToVisitor .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>" .$name. "</td></tr>";
$messageToVisitor .= "<tr><td><strong>City:</strong> </td><td>" .$city. "</td></tr>";
$messageToVisitor .= "<tr><td><strong>Email:</strong> </td><td>" .$toVisitor. "</td></tr>";
$messageToVisitor .= "<tr><td><strong>Phone:</strong> </td><td>" .$phone. "</td></tr>";
$messageToVisitor .= "<tr><td><strong>Comments:</strong> </td><td>" .$comments. "</td></tr>";
$messageToVisitor .= "</table>";
$messageToVisitor .= "</body></html>";
mail($toAdmin, $subjectToAdmin, $messageToAdmin, $headersToAdmin);
mail($toVisitor, $subjectToVisitor, $messageToVisitor, $headersToVisitor);
print "<h3><strong>Thank you for contacting us.</strong> We will get back to you as soon as possible.</h3>
<p>We have received your message and will get in touch with you shortly. If you have any immediate questions please feel free to give us a call. You can find the appropriate contact information for your region on our <a href='/locations/'>locations</a> page.</p>";如果你还需要帮助我解决这个问题,请告诉我。这让我的客户和我自己都快疯了。
提前感谢!
发布于 2012-01-26 20:51:24
您是否尝试过绑定到表单的onsubmit事件而不是按钮?
$('yourformselector').submit(function(e) {
e.preventDefault();
// The rest of your validation script
});发布于 2012-01-26 21:29:38
不要将$("#contact-form").validationEngine('attach', {...});调用附加到发送按钮的单击事件(即,直接在$(document).ready(...);中调用它)。
看起来,对validationEngine('attach', {...})的调用是将一个处理程序附加到表单的submit事件,因此每当用户单击“发送”按钮时,该处理程序就会附加一次。
发布于 2012-01-27 17:42:02
尝试切换您的表单处理脚本到类似的东西,您的问题是,每次您有$messageToVisito,我认为一封电子邮件发送,所以连接您的脚本将有助于和使它更干净。
$to = 'email@test.com';
$subject = 'Test';
$body = '<html><body>';
// concatenated message
'</html></body>';
$headers = '';
mail($to, $subject, $body, $headers);https://stackoverflow.com/questions/9025064
复制相似问题