我正在尝试制作联系表单并收到此一般错误:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, cgiadmin@yourhostingaccount.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
我无法弄清楚如何让它实际记录或回显错误。这是我的php文件:
<?php
ini_set('display_errors', true);
ini_set('log_errors', true);
error_reporting(E_ALL);
ini_set('error_log', 'php.log');
$field_fname = $_GET['fname'] ;
$field_lname = $_GET['lname'] ;
$field_bname = $_GET['bname'] ;
$field_email = $_GET['email'] ;
$field_address = $_GET['address'] ;
$field_city = $_GET['city'] ;
$field_state = $_GET['state'] ;
$field_zip = $_GET['zip'] ;
$field_country = $_GET['country'] ;
$field_comments = $_GET['comments'] ;
$mail_to = 'myemail@mydomain.com';
$subject = 'Message from a site visitor '.$field_fname .$field_lname;
$body_message = 'From: '.$field_fname .$field_lname 'at' .$field_bname "\n";
$body_message = 'E-mail: '.$field_email "\n";
$body_message = 'Address:'.$field_address "\n";
$body_message = 'City:'.$field_city "\n";
$body_message = 'State:'.$field_state "\n";
$body_message = 'Zip Code:'.$field_zip "\n";
$body_message = 'Country:'.$field_country "\n";
$body_message = 'Message: '.$field_comments;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'index.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to myemail@mydomain.com');
window.location = 'index.html';
</script>
<?php
}
?>
我不确定我在做什么是错的。如果有人可以帮我找到错误或指示我记录或回应错误,我会非常感激。
由于
答案 0 :(得分:1)
我把你的代码放在一个名为so.php的文件中 并且它有一个解析错误行20
PHP Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in so.php on line 20
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in so.php on line 20
Errors parsing so.php
您在$field_lname
之后和'at'
之前错过了第20行的连结点
您可能有兴趣在您的系统上进行本地安装php(例如简单的操作)然后将php可执行文件放在您的路径中,这样您就可以运行命令行php -l filename.php
来获取即时解析错误消息就像上面那个。
以下是修复了所有解析错误的代码:
<?php
ini_set('display_errors', true);
ini_set('log_errors', true);
error_reporting(E_ALL);
ini_set('error_log', 'php.log');
$field_fname = $_GET['fname'] ;
$field_lname = $_GET['lname'] ;
$field_bname = $_GET['bname'] ;
$field_email = $_GET['email'] ;
$field_address = $_GET['address'] ;
$field_city = $_GET['city'] ;
$field_state = $_GET['state'] ;
$field_zip = $_GET['zip'] ;
$field_country = $_GET['country'] ;
$field_comments = $_GET['comments'] ;
$mail_to = 'myemail@mydomain.com';
$subject = 'Message from a site visitor '.$field_fname .$field_lname;
$body_message = 'From: '.$field_fname .$field_lname .'at' .$field_bname ."\n";
$body_message = 'E-mail: '.$field_email ."\n";
$body_message = 'Address:'.$field_address ."\n";
$body_message = 'City:'.$field_city ."\n";
$body_message = 'State:'.$field_state ."\n";
$body_message = 'Zip Code:'.$field_zip ."\n";
$body_message = 'Country:'.$field_country ."\n";
$body_message = 'Message: '.$field_comments;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'index.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to myemail@mydomain.com');
window.location = 'index.html';
</script>
<?php
}
?>
答案 1 :(得分:1)
在构建.
时,您缺少一堆连接符($body_message
)。
$body_message = 'From: '.$field_fname .$field_lname.'at' .$field_bname."\n";
$body_message = 'E-mail: '.$field_email."\n";
等等。
任何体面的编辑器都会在您保存文件之前将其标记为错误。
答案 2 :(得分:1)
您可能在默认关闭显示错误的服务器上。您应该能够在脚本中启用它们(假设您无法访问服务器conf或仅在一个脚本上使用它),并在PHP的顶部启用它们:
ini_set("display_errors", "on");
然后它应该输出你的错误。
答案 3 :(得分:0)
您在日志中没有得到任何内容的原因是因为设置错误日志记录和日志文件的php文件包含语法错误,因此无法解析,因此永远不会设置错误日志选项。为避免这种情况,我建议将其放在php.ini文件或.htaccess文件中(如果可能)。您可以在此处查看如何完成此操作:http://perishablepress.com/advanced-php-error-handling-via-htaccess/