调用php脚本时出现内部服务器错误500

调用php脚本时出现内部服务器错误500,php,ajax,Php,Ajax,我试图调用一个php脚本来发送包含联系人表单信息的邮件。在表单被验证之后,我尝试调用scrip,我得到一个500内部服务器错误 这就是我调用脚本的地方 var xmlHttp = new XMLHttpRequest(); //Check if the validation was passed. if($("#contact-form .error-message").size() === 0) { xmlHttp.open("POST", "scripts/send_mail.ph

我试图调用一个php脚本来发送包含联系人表单信息的邮件。在表单被验证之后,我尝试调用scrip,我得到一个500内部服务器错误

这就是我调用脚本的地方

var xmlHttp = new XMLHttpRequest();
//Check if the validation was passed.
if($("#contact-form .error-message").size() === 0) {

    xmlHttp.open("POST", "scripts/send_mail.php");
    xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlHttp.send("name="+name.value+"&email="+email.value+"&message="+message.value+"&g-recaptcha-response="+captcha);
}
这就是所谓的脚本

<?php
require_once '../init.php';

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$captcha = $_POST['g-recaptcha-response'];

$from = 'noreply@hotmail.com';
$to = 'mymail@hotmail.com';
$subject = 'Message from ' . $name;
$body ="From: $name\n E-Mail: $email\n Message:\n $message";

//Verify the captcha by sending a POST-request to Google's server.
$url = 'https://www.google.com/recaptcha/api/siteverify';
$data = array('secret' => 'xxx', 'response' => $captcha);
$options = array(
'http' => array(
    'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
    'method'  => 'POST',
    'content' => http_build_query($data),
),
);
$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$result = json_decode($result, true);



//If the verification of the captcha was successful.
if($result['success']) {

mail($to, $subject, $body, $from)

echo "Thank you! Your message has been received.";
}
else echo "Failed to submit, please try again.";

您需要在行中添加一个结束分号:

mail($to, $subject, $body, $from)
应该是

mail($to, $subject, $body, $from);

启用php错误报告并给出确切的错误。查看服务器错误日志以了解有关错误的详细信息。哦,谢谢你的谷歌密钥。在整个代码中添加日志消息,查看服务器日志,用硬编码变量替换帖子,在浏览器中打开页面,或者至少说你尝试了什么,得到了什么结果……哇,我怎么没看到。。。谢谢