不确定这里错误报告第9行是否错误,但是当我看起来代码不匹配时。
错误讯息:
解析错误:语法错误,意外T_STRING,期待第9行/home/hletf/public_html/mailform.php中的'{'
请原谅表格。
HTML FORM CODE:
<form id="form1" name="form1" method="post" action="mailform.php">
<table width="90%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="48%"><div align="right"><h3>Name:</h3></div></td>
<td width="52%"><input type="text" name="NAME" id="NAME" /></td>
</tr>
<tr>
<td><div align="right"><h3>Email:</h3></div></td>
<td><input type="text" name="EMAIL" id="EMAIL" /></td>
</tr>
<tr>
<td><div align="right"><h3>Comment:</h3></div></td>
<td><textarea name="COMMENT" id="COMMENT" cols="45" rows="5"></textarea></td>
</tr>
<tr>
<td><div align="right"></div></td>
<td>
<input type="image" name="SUBMIT" id="SUBMIT" src="images/submit_button.jpg" width="81" height="23" />
</td>
</tr>
</table>
</form>
MAILFORM.PHP:
<?PHP
define('kOptional', true);
define('kMandatory', false);
error_reporting(E_ERROR | E_WARNING | E_PARSE);
ini_set('track_errors', true);
function DoStripSlashes($fieldValue) {
// temporary fix for PHP6 compatibility - magic quotes deprecated in PHP6
if ( function_exists( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc() ) {
if (is_array($fieldValue) ) {
return array_map('DoStripSlashes', $fieldValue);
} else {
return trim(stripslashes($fieldValue));
}
} else {
return $fieldValue;
}
}
function FilterCChars($theString) {
return preg_replace('/[\x00-\x1F]/', '', $theString);
}
function CheckEmail($email, $optional) {
if ( (strlen($email) == 0) && ($optional === kOptional) ) {
return true;
} elseif ( eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email) ) {
return true;
} else {
return false;
}
}
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$clientIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$clientIP = $_SERVER['REMOTE_ADDR'];
}
$FTGNAME = DoStripSlashes( $_POST['NAME'] );
$FTGEMAIL = DoStripSlashes( $_POST['EMAIL'] );
$FTGCOMMENT = DoStripSlashes( $_POST['COMMENT'] );
$FTGSUBMIT = DoStripSlashes( $_POST['SUBMIT'] );
$validationFailed = false;
# Fields Validations
if (!CheckEmail($FTGEMAIL, kMandatory)) { $validationFailed = true; }
# Redirect user to the error page
if ($validationFailed === true) {
header("Location: http://www.glustik.com/error.html");
}
if ( $validationFailed === false ) {
# Email to Form Owner
$emailSubject = FilterCChars("OMG - Test");
$emailBody = "NAME : $FTGNAME\n"
. "EMAIL : $FTGEMAIL\n"
. "COMMENT : $FTGCOMMENT\n"
. "SUBMIT : $FTGSUBMIT\n"
. "";
$emailTo = 'James <james@glustik.com>';
$emailFrom = FilterCChars("$FTGEMAIL");
$emailHeader = "From: $emailFrom\n"
. "MIME-Version: 1.0\n"
. "Content-type: text/plain; charset=\"UTF-8\"\n"
. "Content-transfer-encoding: 8bit\n";
mail($emailTo, $emailSubject, $emailBody, $emailHeader);
# Redirect user to success page
header("Location: http://www.glustik.com/thanks.html");
}
?>
答案 0 :(得分:1)
使用以下功能更改您的功能:
function DoStripSlashes($fieldValue){
// temporary fix for PHP6 compatibility - magic quotes deprecated in PHP6
if ( function_exists( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc() ) {
if (is_array($fieldValue) ) {
return array_map('DoStripSlashes', $fieldValue);
} else {
return trim(stripslashes($fieldValue));
}
} else {
return $fieldValue;
}
}