加载资源失败,空白页



您好,感谢您查看我的问题,我的一个表单显示白色屏幕时遇到问题。我收到错误"加载资源失败:服务器响应状态为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"); 

该错误很可能是由于您在仍要发送标头时发送内容引起的。这将导致一个错误被触发,类似于"试图修改已发送内容的标题信息">

将重定向放到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文件的开头。

最新更新