[英]500 internal server error when doing ajax request
I'm having trouble investigating an 500 Internal Server Error I get when trying to do an AJAX request ( I'm doing a "PUT" / "GET" ) on my server. 我在尝试在服务器上执行AJAX请求(我正在执行“ PUT” /“ GET”)时遇到500内部服务器错误时遇到问题。
Locally it runs without any issues and it responds, but after I uploaded the content on the server it doesn't, as if the file / folder wouldn't be there. 它在本地运行没有任何问题,并且可以响应,但是在我将内容上载到服务器后,它没有显示,就好像文件/文件夹不存在一样。
The host is running on Apache with PHP at least version 5.3.0 since I last checked. 自从我上次检查以来,该主机正在Apache上运行,PHP版本至少为5.3.0。 I get the error when trying to use the footer newsletter subscribe.
尝试使用页脚新闻订阅时收到错误消息。
My index file which is requested when doing the AJAX looks like the following : 执行AJAX时要求的我的索引文件如下所示:
<?php
/*
* Import PHPMailer Class
*/
require("phpmailer/class.phpmailer.php");
/*
* Decode JSON Data
*/
$request = json_decode(file_get_contents("php://input"), true);
/*
* Check Valid Email Address
*/
if (!filter_var($request["Email"], FILTER_VALIDATE_EMAIL)) {
echo json_encode([
"error" => true,
"message"=> "You must enter a valid email address"
]);
return false;
};
/*
* Instantiate PHPMailer Class
*/
$mailer = new PHPMailer();
/*
* Set Reply Settings
*/
$reply_email = "no-reply@barbershoppen.dk";
$reply_name = "Barber Shoppen";
/*
* Specific PHPMailer Settings
*/
$mailer->IsSMTP(); /* SMTP Usage */
$mailer->SMTPAuth = true; /* SMTP Authentication */
$mailer->SMTPSecure = "ssl"; /* Sets Servier Prefix */
$mailer->Host = "smtp.gmail.com"; /* SMTP Server */
$mailer->Port = 465; /* SMTP Port */
$mailer->Username = "rolandeveloper@gmail.com"; /* SMTP Account Username */
$mailer->Password = "333333333"; /* SMTP Account Password */
/*
* Email Settings
*/
$mailer->SetFrom($reply_email, $reply_name);
$mailer->AddReplyTo($reply_email, $reply_name);
$mailer->AddAddress($request["Email"]);
$mailer->Subject = "Barber Shoppen [ Confirmation Email ]";
$mailer->Body = "You have successfully subscribed to our newsletter";
$mailer->isHTML(true);
/*
* Send Email
*/
if($mailer->Send()) {
echo json_encode([
"error" => false,
"message"=> "You have successfully subscribed"
]);
} else {
echo json_encode([
"error" => true,
"message"=> $mailer->ErrorInfo
]);
};
?>
I would appreciate some help or some pointers in which directions I should head and fix this error. 我将不胜感激,应该提供一些帮助或指导,以指示我应该改正这个错误的方向。
You want to pass in a PHP-style array instead of a javascript-style array into json_encode: 您想要将PHP样式的数组而不是JavaScript样式的数组传递到json_encode中:
if (!filter_var($request["Email"], FILTER_VALIDATE_EMAIL)) {
echo json_encode(array(
"error" => true,
"message"=> "You must enter a valid email address"
));
return false;
};
And: 和:
if($mailer->Send()) {
echo json_encode(array(
"error" => false,
"message"=> "You have successfully subscribed"
));
} else {
echo json_encode(array(
"error" => true,
"message"=> $mailer->ErrorInfo
));
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.