我有一个PHP邮件表单,我已经设置了使用AJAX& jQuery验证并提交表单。一切似乎工作正常,但无论出于何种原因,我的客户(网站所有者)收到每个邮件发送的多个副本。副本的数量从每封邮件的1到10份不等,没有特定的模式。
在我完成的所有测试中,我个人只在我的公司电子邮件地址和另一个Gmail帐户上收到1份邮件。然而,其域名注册商托管其电子邮件帐户的客户端一次最多可以获得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>";
让我知道是否还有其他任何东西可以帮助我解决这个问题。这让我的客户和我自己疯狂。
提前致谢!
答案 0 :(得分:0)
您是否尝试过绑定到表单的onsubmit事件而不是按钮?
$('yourformselector').submit(function(e) {
e.preventDefault();
// The rest of your validation script
});
答案 1 :(得分:0)
请勿将$("#contact-form").validationEngine('attach', {...});
调用附加到发送按钮的点击事件(即直接在$(document).ready(...);
内调用)。
看起来对validationEngine('attach', {...})
的调用正在将一个处理程序附加到表单的submit
事件,因此每次用户单击发送按钮时,此处理程序都会附加一次。
答案 2 :(得分:0)
尝试将您的表单处理脚本切换为类似的内容,您的问题是每次有$ messageToVisito时,我认为电子邮件发送,因此连接您的脚本会有所帮助并使其更清晰。
$to = 'email@test.com';
$subject = 'Test';
$body = '<html><body>';
// concatenated message
'</html></body>';
$headers = '';
mail($to, $subject, $body, $headers);