1

我无法调查在我的服务器上尝试执行 AJAX 请求(我正在执行“PUT”/“GET”)时遇到的 500 Internal Server Error。

在本地它运行没有任何问题并且它响应,但是在我将内容上传到服务器后它没有,好像文件/文件夹不存在一样。

自从我上次检查以来,主机运行在 Apache 上,PHP 版本至少为 5.3.0。尝试使用页脚时事通讯订阅时出现错误。

执行 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
    ]);

};
?>

我将不胜感激一些帮助或一些指示,我应该朝哪个方向前进并修复此错误。

4

1 回答 1

5

您想将 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;
};

和:

if($mailer->Send()) {

    echo json_encode(array(
        "error" => false,
        "message"=> "You have successfully subscribed"
    ));

} else {

    echo json_encode(array(
        "error" => true,
        "message"=> $mailer->ErrorInfo
    ));

};
于 2013-05-22T18:45:26.200 回答