我的script.js和php邮件不匹配 [英] my script.js and php mail do not match
本文介绍了我的script.js和php邮件不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I'm at the end of my rope and was hoping someone could help me out. I took over for someone and have been trying to have my form send via ajax POST but the mail.php I've been using does not send even though I get a 200 OK. I did a test on conetix and it sent but I must be missing something. Any help is greatly appreciated. Here is the relevant script:
$("#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;
}
and here is my 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";
?>
Again, any help would really keep me from tearing my eyes out.
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('');
}
});
}
推荐答案
( #send)。click(function(){
var valid = ' ';
var isr = ' 是必需的!< / p>' ;
var name =
("#send").click(function(){ var valid = ''; var isr = ' is required!</p>'; var name =
( < span class =code-string>#name)。val();
var mail =
("#name").val(); var mail =
( #mail)。val();
var messaggio =
("#email").val(); var messaggio =
这篇关于我的script.js和php邮件不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文