联系我们的电子邮件PHP错误

问题描述:

我试图做一个联系表,我得到这个通用错误:联系我们的电子邮件PHP错误

Internal Server Error 

The server encountered an internal error or misconfiguration and was unable to complete your request. 

Please contact the server administrator, [email protected] 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 = '[email protected]'; 
$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 [email protected]'); 
     window.location = 'index.html'; 
    </script> 
<?php 
} 
?> 

我不知道我在做什么是错的。如果有人能够帮助我找到错误或指示我登录或回应错误,我会非常感激。

感谢

+0

什么版本的PHP?在5.4之前,你应该做'error_reporting(E_ALL | E_STRICT)'。看到这里:http://php.net/manual/en/function.error-reporting.php – Raekye 2013-03-21 22:07:31

+0

你也错过了20号线上的另一个时期,一个21,一个22,一个23,一个24,一个25和26上的一个。 – 2013-03-21 22:12:12

构建$body_message当你丢失级联器的堆(.)。

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

等等。

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

我把你的代码在一个名为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

你错过在之后的第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 = '[email protected]'; 
$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 [email protected]'); 
     window.location = 'index.html'; 
    </script> 
<?php 
} 
?> 
+0

谢谢我现在看到并修复了它。尽管如此,我仍然遇到了一般错误。生病继续搜索 – vman411gamer 2013-03-21 22:20:31

+0

也许值得一提的是,PHP中的邮件功能在许多共享服务器上被禁用。 – 2013-03-21 22:24:52

+0

尝试注释邮件行并查看它是否不再提供通用服务器错误。 – 2013-03-21 22:25:23

您很可能在默认情况下关闭显示错误的服务器上。你应该能够让他们在脚本(假设你不能访问服务器的conf或只希望它为一个脚本)在你的PHP的顶部,这样的:

ini_set("display_errors", "on"); 

那么就应该输出你的错误。

+0

不幸的是,大多数服务器配置不会给你分析错误的行号。在命令行模式下,'php -l'对于这类事情非常有用。 – 2013-03-21 22:13:07

+1

你知道,我从来没有shell访问服务器,我无法display_errors,所以我从来没有遇到过。这就是为什么我开发一个不同的系统...... – 2013-03-21 22:15:45

+0

是的,如果一个人运行Windows操作系统,他们可以安装wamp并将包含php.exe的目录添加到他们的路径中,并运行我在说的命令行模式lint check。 +1为您在开发期间关闭display_errors的建议! – 2013-03-21 22:18:43

你在日志中没有得到任何东西的原因是因为设置错误日志和日志文件的php文件包含语法错误,因此无法解析,所以错误日志选项从不设置。为了避免这种情况,我建议把它放在php.ini文件或者.htaccess文件中,如果可能的话。你可以看到这是如何完成的:http://perishablepress.com/advanced-php-error-handling-via-htaccess/