PHP文件中出现意外的$ end

Mat*_*aly 1 php

我正在开发一个PHP联系表单,但我无法让它工作.我在Apache服务器日志中遇到以下错误,在Ubuntu服务器VM上运行:

PHP Parse error:  syntax error, unexpected $end in /home/matthew/Sites/contactFormResponse.php on line 75, referer: http://192.168.1.4/contactForm.php
Run Code Online (Sandbox Code Playgroud)

从谷歌搜索这个错误,听起来它通常是由于服务器没有设置识别它们时使用短PHP标签,或者是由于没有正确关闭的代码块.但据我所知,情况并非如此 - 据我所知,它已全部正确关闭.它引用的行是超过文件末尾的一行.

这是PHP代码:

 <?php
                                    error_reporting(E_ALL);
                                    // Define variables to hold the name, email address and message, and import the information into the variables
                                    $name = $_POST['NameInput'];
                                    $email = $_POST['EmailAddress'];
                                    $telno = $_POST['ContactNumber'];
                                    $querytype = $_POST['QueryType'];
                                    $bookingstartdate = $_POST['BookingStartDay'] . $_POST['BookingStartMonth'] . $_POST['BookingStartYear'];
                                    $bookingenddate = $_POST['BookingEndDay'] . $_POST['BookingEndMonth'] . $_POST['BookingEndYear'];
                                    $message = $_POST['QueryText'];

                                    // Validate the inputs - send it if it's OK
                                    if(3 < strlen($name) && 3 < strlen($email))
                                    {
                                            $email_message = <<< EMAIL
                                                    Message from contact form at holidaychalet.co.uk
                                                    Name: $name
                                                    Email: $email
                                                    Contact Number: $telno
                                                    Query Type: $querytype
                                                    Booking Start Date: $bookingstartdate
                                                    Booking End Date: $bookingenddate
                                                    The message:
                                                    $message
                                                    EMAIL;
                                            $headers = "cc:me@myemailaddress.com\r\n";
                                            if(mail('matthew@localhost','Contact form email', $email_message, $headers))
                                            {
                                                    echo "Thanks for completing the form! I'll be in touch shortly!";
                                            }
                                            else
                                            {
                                                    echo "Something went wrong - please use the back button and try again";
                                            }
                                    }
                                    else
                                    {
                                            echo "You didn't complete the form fully enough! Please use go back using your web browser's back button";
                                    }
                            ?>
Run Code Online (Sandbox Code Playgroud)

Gum*_*mbo 5

here文档语法的结束标识符必须位于行的开头,没有任何缩进:

请注意,具有结束标识符的行必须不包含其他字符,除非可能是分号(;).这尤其意味着标识符可能没有缩进,并且在分号之前或之后可能没有任何空格或制表符.同样重要的是要认识到结束标识符之前的第一个字符必须是本地操作系统定义的换行符.

所以在你的情况下:

                                            $email_message = <<< EMAIL
                                                    Message from contact form at holidaychalet.co.uk
                                                    Name: $name
                                                    Email: $email
                                                    Contact Number: $telno
                                                    Query Type: $querytype
                                                    Booking Start Date: $bookingstartdate
                                                    Booking End Date: $bookingenddate
                                                    The message:
                                                    $message
EMAIL;
Run Code Online (Sandbox Code Playgroud)