我有一个我正在调用的函数来验证一个recaptcha,然后根据验证是否成功,发送一封电子邮件。我正在使用 jquery .ajax 函数验证 recaptcha,并在成功验证后使用另一个 jquery .ajax 函数发送电子邮件。
这是javascript:
function validateCaptcha(){
var isValid = $('#es_contact_form').valid();
var esform = $('#es_contact_form').serialize();
var html = $.ajax({
type: "POST",
url: "scripts/ajax.recaptcha.php",
data: esform,
async: false
}).responseText;
if(isValid)
{
if(html == "success")
{
//alert("Captcha and form are valid");
//return true;
var esform2 = $('#es_contact_form').serialize();
var response = $.ajax({
type: "POST",
url: "scripts/ajax.email.php",
data: esform2,
async: false
}).responseText2;
if(response=="success")
{
alert('mail successfully sent');
return true;
}else{
alert('mail not sent, please try again');
Recaptcha.reload();
return false;
}
}
else
{
alert('Form valid, captcha bogus');
$("#captchaStatus").html("Your captcha is incorrect. Please try again");
Recaptcha.reload();
return false;
}
}else{
if(html == "success")
{
//alert("Captcha's good, but the form aint!");
Recaptcha.reload();
return false;
}
else
{
//alert('Form invalid, captcha bogus...can you do anything right?');
$("#captchaStatus").html("Your captcha is incorrect. Please try again");
Recaptcha.reload();
return false;
}
}
}
这是我收到 500 服务器错误的脚本的服务器端代码:
<?php
$yourName = 'ES';
$yourEmail = 'rob@domain.com';
$yourSubject = 'ES: contact form';
$referringPage = 'es.domain.com';
function cleanPosUrl ($str) {
$nStr = $str;
$nStr = str_replace("**am**","&",$nStr);
$nStr = str_replace("**pl**","+",$nStr);
$nStr = str_replace("**eq**","=",$nStr);
return stripslashes($nStr);
}
if ( isset($_POST) ) {
$to = $yourEmail;
$subject = $yourSubject;
$message = cleanPosUrl($_POST['name'])."\r\n\n";
$message .= cleanPosUrl($_POST['remail'])."\r\n\n";
$message .= cleanPosUrl($_POST['phone'])."\r\n\n";
$message .= cleanPosUrl($_POST['comments']);
$headers = "From: ".cleanPosUrl($_POST['name'])." <".cleanPosUrl($_POST['remail']).">\r\n";
$headers .= 'To: '.$yourName.' <'.$yourEmail.'>'."\r\n";
$mailit = mail($to,$subject,$message,$headers);
}
if ( $mailit )
{ ?>success<? }
else
{ die ("The mail wasn't sent"); }
}
?>
ajax.recaptcha.php 和 ajax.email.php 都从帖子中提取,如果成功则返回“成功”。
ajax.recaptcha.php 工作正常。但是当它到达 ajax.email.php 脚本时,我在 Firebug 中不断收到 500 服务器错误。
有没有人知道为什么一个会工作而不是另一个?这些脚本都在同一台服务器上的同一个文件夹中,所以我不明白为什么这不起作用。
任何帮助是极大的赞赏。
谢谢