https://bpaste.net/show/557a8418f211
该链接包含我遇到的错误。似乎我在某处缺少一个右括号,我无法弄清楚。当我将右括号添加到主 if 语句时,它在结束 PHP 标记中给我一个错误。当我删除它时,我在该行收到错误消息。
[root@li71-58 html]# php testmail.php
PHP Warning: Zend OPcache huge_code_pages: madvise(HUGEPAGE) failed: Invalid argument (22) in Unknown on line 0
PHP Parse error: syntax error, unexpected end of file in /var/www/html/testmail.php on line 70
[root@li71-58 html]#
在else之后你已经留下了一个大括号,现在使用这段代码
<?php
// define variables and set to empty values
$lnameErr = $emailErr = $fnameErr = "";
$fname = $emailaddr = $lname = $phone = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["fname"])) {
$fnameErr = "First name is required";
}
else {
$fname = test_input($_POST["fname"]);
// check if name only contains letters and whitespace for first name
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$nameErr = "Only letters and white space allowed";
}
}
if (empty($_POST["lname"])) {
$lnameErr = "Last name is required";
}
else {
$lname = test_input($_POST["lname"]);
// check if name only contains letters and whitespace for last name
if (!preg_match("/^[a-zA-Z ]*$/",$lname)) {
$lnameErr = "Only letters and white space allowed";
}
}
if (empty($_POST["email"])) {
$emailErr = "Email is required";
}
else {
$email = test_input($_POST["email"]);
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}
}
}
// Passes input to email
else {
(isset($_POST['firstname']) && isset($_POST['lastname']) && isset($_POST['email'])
&& isset($_POST['phone']) && isset($_POST['county']) && isset($_POST['floor'])
&& isset($_POST['descr'])); {
$data = $_POST['firstname'] . ' ' . $_POST['lastname'] . "\n" .
$_POST['email'] . "\n" . $_POST['phone'] . "\n" .
$_POST['county'] . "\n" . $_POST['floor'] . "\n" . $_POST['descr'] . "\n";
mail('craftsllc1@gmail.com', 'Estimation Inquery', $data);
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
echo "Thank you for your inquery! <br/> An estimator will be with right with you";
?>
这是你错过花括号的地方
// Passes input to email
else {
(isset($_POST['firstname']) && isset($_POST['lastname']) && isset($_POST['email'])
&& isset($_POST['phone']) && isset($_POST['county']) && isset($_POST['floor'])
&& isset($_POST['descr'])); {
$data = $_POST['firstname'] . ' ' . $_POST['lastname'] . "\n" .
$_POST['email'] . "\n" . $_POST['phone'] . "\n" .
$_POST['county'] . "\n" . $_POST['floor'] . "\n" . $_POST['descr'] . "\n";
mail('craftsllc1@gmail.com', 'Estimation Inquery', $data);
}
} // this is brace you missed