您好,感谢您查看我的问题,我目前有一个表单显示白色屏幕的问题。我收到错误消息“无法加载资源:服务器响应状态为500”。发生的情况是,一旦填写了我的表格,然后单击“提交”,您将被定向到该空白页面,而不是看到应该显示的消息,请找到以下代码:

<?php
// Using PHP mailer from
$siteroot = "/home/externships/public_html" ;


//these are variables specific to the form
$usecsv = false;
//$csv_file = "test-student-mentor.csv";
$recipient1 = "[email protected]";
//$recipient1 = "[email protected]";

$sendtouser = false; // if true, send email to person who filled out form
$replyemail = "[email protected]";

$url = $_SERVER["HTTP_REFERER"];
$formresults = '';

require_once ($siteroot . "/_include/formvalidator.php");
$validator = new FormValidator();

// Now, validate the form
if($validator->ValidateForm())
{

    $subject = $processed_form_variables['subject'];
    $redirect = $processed_form_variables['redirect'];
    unset($processed_form_variables['Submit']);
    unset($processed_form_variables['_pid']);
    unset($processed_form_variables['_fid']);
    unset($processed_form_variables['recipient']);
    unset($processed_form_variables['subject']);
    unset($processed_form_variables['redirect']);


    require_once ($siteroot . "/_include/form_results_for_email.php");

    $messagebody = "<p>You have a response from the Externship site " . $url . "</p><p>" . $formresults . "</p>";
    // send email via gmail
    require_once ($siteroot . "/_include/send_gmail.php");

    if(!$mail->Send()):
        echo "Message could not be sent. <p>";
        echo "Mailer Error: " . $mail->ErrorInfo;
        // else:                            // uncomment for testing
        //  echo "Message has been sent";   // uncomment for testing
    endif;

    header("Location: $redirect");
    exit;
}
header("Location: $url");

最佳答案

该错误最有可能是由于您仍想发送标题时发送内容引起的。
这将导致“尝试用已发送的内容修改标题信息”触发错误。

将您的重定向放入if语句的else部分,然后退出。

    ....
    if(!$mail->Send()):
        echo "Message could not be sent. <p>";
        echo "Mailer Error: " . $mail->ErrorInfo;
        // else:                            // uncomment for testing
        //  echo "Message has been sent";   // uncomment for testing
    else:
        header("Location: $redirect");
    endif;


    exit;
}
header("Location: $url");


您已禁用错误报告,这将导致您看不到该错误。查看php错误日志,或在php.ini(display_errors = on)中将其打开或使用

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);


在执行错误代码之前,首先在您的php文件中。

关于javascript - 加载资源失败,空白页,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51675851/

10-10 02:33