我在绳子的尽头,希望有人可以帮助我。我接管了某人并且一直试图通过ajax POST发送我的表单,但即使我得到了200 OK,我一直在使用的mail.php也没有发送。我对conetix进行了测试并发送但我必须遗漏一些东西。任何帮助是极大的赞赏。以下是相关脚本:
$("#send").click(function(){
var valid = '';
var isr = ' is required!</p>';
var name = $("#name").val();
var mail = $("#email").val();
var messaggio = $("#message").val();
if (name.length<1) {
valid += '<p>*Valid name'+isr;
}
if (!mail.match(/^([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4}$)/i)) {
valid += '<p>*Valid email address'+isr;
}
这是我的php:
<?php
/// Here we get all the information from the fields sent over by the form.
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = 'xxx@xxx.com';
$subject = 'Contact Us Form Submission';
$message = 'FROM: '.$name.' Email: '.$email.'Message: '.$message;
$headers = 'From: xxx@xxx.com' . "\r\n";
?>
再一次,任何帮助都会让我不再睁开眼睛。
if (valid!='') {
$("#response").fadeIn("slow");
$("#response").html(valid);
$('#send').removeClass('normal').addClass('error-button');
$('#send').val('');
setTimeout(function() {
$('#send').removeClass('error-button').addClass('normal');
$('#send').val('send');
$("#response").fadeOut("slow");
}, 3000);
}
else {
var datastr ='name=' + name + '&mail=' + mail + '&messaggio=' + encodeURIComponent(messaggio);
setTimeout("send('"+datastr+"')",1000, $('#send').val('wait...'));
}
return false;
});
}(jQuery的))
function send(datastr){
$.ajax({
type: "POST",
url: "phptest.php",
data: datastr,
cache: false,
success: function(html){
$('#send').removeClass('normal, error-button').addClass('send-email');
$('#send').val('');
}
});
}
答案 0 :(得分:1)
您的数据字符串如下所示:
'&mail=' + mail
'&messaggio='
虽然你的PHP抓住了这个:
$_POST['email'];
$_POST['message'];
'mail'!='email'和'messaggio'!='message'