4

在我的 PHP 代码中,我有一个变量$message,其中包含要发送给我的消息,其中包含 post 变量。它应该在末尾有一个分号......但它给了我一个错误,说它是意外的,但我知道我需要它,因为没有它它就无法工作。我完全不知所措。希望这里有人可以帮助我。

错误信息:

PHP Parse error:  syntax error, unexpected ';'

PHP 代码

if(!empty($_POST["name"]) && !empty($_POST["address"]) && !empty($_POST["city"]) && !empty($_POST["phone"]) && !empty($_POST["email"]) && !empty($_POST["type"]))
{
$message = "Name:" . $_POST["name"] . 
"Address:" . $_POST["address"] . 
"City:" . $_POST["city"] . 
"State:" . $_POST["state"] . 
"Zip Code:" . $_POST["zip"] . 
"Phone:" . $_POST["phone"] . 
"Email:" . $_POST["email"] . 
"Current Roof Type:" . $_POST["type"] . 
"Roof Age:" . $_POST["age"] .
"Is it leaking?:" . $_POST["leak"] . 
"Does it have hail damage?:" . $_POST["hail"] . 
"Insurance:" . $_POST["insurance"] . 
"Additional Comments:" . $_POST["extra"] . 
;                                          <---------------####Unexpected semicolon
$to = "emailasdasdasdasd";
$subject = "Free Estimate";
$from = "Guarantee Roofing";
$headers = "From:" . $_POST["name"];
mail($to,$subject,$message,$headers);
}
4

5 回答 5

5
"Additional Comments:" . $_POST["extra"] .  
                                         ^

Unnecessary concatenation operator -----------------here.

PHP is expecting a string/variable next to the concatenation operator and finds semicolon, which is reported unexpected.

于 2012-10-18T18:26:23.877 回答
2
"Additional Comments:" . $_POST["extra"] . 
                                         ^---- dangling concatenation
;  

you're telling PHP to concatenate a couple strings, and then terminate the statement without providing the second string.

于 2012-10-18T18:26:27.403 回答
2

here is the problem

 "Additional Comments:" . $_POST["extra"] . 
 ;

should be

  "Additional Comments:" . $_POST["extra"]   ;
于 2012-10-18T18:27:58.153 回答
1

There's an extra dot at the end of the string, if you delete the line breaks, you'd end up with

 ... . "Additional Comments:" . $_POST["extra"] . ;
于 2012-10-18T18:26:55.677 回答
0

You don't need that extra . after the last line which is implying concatenation.

Remove the . after this line:

"Additional Comments:" . $_POST["extra"] .
于 2012-10-18T18:27:00.857 回答