0

我正在尝试制作联系表格并收到此一般错误:

    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
}
?>

我不确定我在做什么是错的。如果有人可以帮助我找到错误或指导我记录或回显错误,我将不胜感激。

谢谢

4

4 回答 4

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你错过了第 20 行前后的连接点'at'

您可能有兴趣在您的系统上本地安装 php(例如简单的 wamp),然后将 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
}
?>
于 2013-03-21T22:09:08.200 回答
1

.在构建$body_message.

$body_message = 'From: '.$field_fname .$field_lname.'at' .$field_bname."\n";
$body_message = 'E-mail: '.$field_email."\n";

等等。

任何体面的编辑器都会在您保存文件之前将此标记为错误。

于 2013-03-21T22:11:00.037 回答
1

您可能在默认情况下关闭显示错误的服务器上。您应该能够在脚本中启用它们(假设您无法访问服务器 conf 或只希望在一个脚本中启用它们),并在 PHP 的顶部使用它:

ini_set("display_errors", "on");

然后它应该输出你的错误。

于 2013-03-21T22:12:15.843 回答
0

您在日志中没有得到任何内容的原因是因为设置错误日志和日志文件的 php 文件包含语法错误,因此无法解析,因此永远不会设置错误日志选项。为避免这种情况,我建议将其放在 php.ini 文件或 .htaccess 文件中(如果可能)。你可以在这里看到这是如何完成的:http: //perishablepress.com/advanced-php-error-handling-via-htaccess/

于 2013-03-21T22:23:44.290 回答