加载资源失败,空白页

时间:2018-08-03 15:27:54

标签: javascript php

您好,感谢您回答我的问题,我目前有一个表单显示白色屏幕的问题。我收到错误消息“无法加载资源:服务器响应状态为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 = "example@mail.com";
//$recipient1 = "example@mail.com";

$sendtouser = false; // if true, send email to person who filled out form
$replyemail = "example@mail.com";

$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"); 

1 个答案:

答案 0 :(得分:1)

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

将重定向重定向到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文件中