我是一个初学者,但我已经设法为我的网站整理了一份反馈表。我遇到的问题是表单是发送2封电子邮件而不是1封。是否有任何关于导致此问题的想法?
$('#myForm')
.on('valid.fndtn.abide', function () {
var name = $("input#name").val();
var email = $("input#email").val();
var message = $("textarea#message").val();
var dataString = 'name=' + name +
'&email=' + email +
'&message=' + message;
$.ajax({
type: "POST",
url: "/contact/mail.php",
data: dataString,
success: function() {
$('.contactform').html("<div id='thanks'></div>");
$('#thanks').html("<h2>Thanks!</h2>")
.append("<p>Dear "+ name +"!, We will get back to you as soon as we can.</p>")
.hide()
.fadeIn(1500);
},
}); //ajax call
return false;
});
PHP:
<?php
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];
$msg = "
Name: $name
Email: $email
Comments:
$message
";
$to = "email@example.com";
$subject = "Website";
$message = $msg;
$headers = "Website";
mail($to,$subject,$message,$headers);
?>
答案 0 :(得分:0)
显然,基金会5仍然包含来自先前版本的旧呼叫功能&#34;有效&#34; vs&#34; valid.fndtn.abide&#34;导致它被调用两次。通过进行以下更改,我能够阻止双重电子邮件:
$('#myForm')
.on('valid.fndtn.abide', function (e) {
if(e.namespace != 'abide.fndtn') {
return;
}
var name = $("input#name").val();
var email = $("input#email").val();
var message = $("textarea#message").val();