解析错误:语法错误,文件意外结束

时间:2012-10-25 11:20:25

标签: php parsing

你能帮忙我得到一个Parse错误:语法错误,第42行的C:\ xampp \ htdocs \ xampp \ form-to-email.php中的文件意外结束,想知道你是否可以帮我解决这个问题我很困惑......

<?php    {   
    if(!isset($_POST['submit']))
    {
    //This page should not be accessed directly. Need to submit the form.
    echo "error; you need to submit the form!";

    $name = $_POST['name'];
    $attend = $_POST['attend'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $office = $_POST['office'];
    $starter = $_POST['starter'];
    $mainmeal = $_POST['mainmeal'];
    $specialdietaryrequirements = $_POST['specialdietaryrequirements'];
    $otherdietaryrequirements = $_POST['otherdietaryrequirements'];
    $nameofguest = $_POST['nameofguest'];
    $starterguest = $_POST['starterguest'];
    $mainmealguest = $_POST['mainmealguest'];
    $guestspecialdietaryrequirements = $_POST['guestspecialdietaryrequirements'];
    $guestotherdietaryrequirements = $_POST['guestotherdietaryrequirements'];
    //email body
    $email_from = 'my@email.com';
    $email_subject = "Christmas Part Submission";
    $email_body = "You have received a new message from the user $name.\n".
    "Are you attending: $attend \n".
    "Email address from the person: $email \n".
    "Contact number: $phone \n".
    "Office: $office \n".
    "Starter: $starter \n".
    "Main Meal: $mainmeal \n".
    "Special Dietary Requirements: $specialdietaryrequirements \n".
    "Other Dietary Requirements: $otherdietaryrequirements \n".
    "Name of Guest: $nameofguest \n".
    "Guest Starter: $starterguest \n".
    "Guest Main Meal: $mainmealguest \n".
    "Guest Special Dietary requirements: $guestspecialdietaryrequirements \n".
    "Guest other Dietary requirements: $guestotherdietaryrequirements \n".
    // who it is being sent too (edit this)
    $to = "my@email.com";
    $headers = "From: $email_from \r\n";
    mail($to,$email_subject,$email_body,$headers);
    {   ?>

4 个答案:

答案 0 :(得分:1)

替换它:

<?php    {   
if(!isset($_POST['submit']))
{

<?php  
if(!isset($_POST['submit']))
{

,长代码最后的{应为}

答案 1 :(得分:0)

从它的外观来看,你忘了关闭你的if语句和之前发生的任何事情。  尝试替换

{

在文件末尾

 }
}

答案 2 :(得分:0)

末尾的最后一个大括号必须更改为结束大括号

答案 3 :(得分:0)

仅限第一行

<?php

否{

最后一行: 你必须关闭IF标签才能打开它!

}

<?php       
    if(!isset($_POST['submit']))
    {
    ...
    mail($to,$email_subject,$email_body,$headers);
    }   
?>