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

时间:2015-06-02 14:03:05

标签: php ajax

我试图调用php脚本发送包含联系表单信息的邮件。表单验证后,我尝试调用脚本即时获取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.";

有谁知道可能导致这种情况的原因?提前致谢

1 个答案:

答案 0 :(得分:2)

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

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

应该是

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