如何解决此联系表单的语法错误,PHP中意外的T_IF错误?

时间:2019-09-16 05:54:15

标签: php

我不知道为什么我的联系表格出现此错误,我是php的新手。希望你能帮助我

  

解析错误:语法错误,第2行出现意外的'if'(T_IF)

代码

<? php
    if (isset($_POST['submit'])) { 
       $name = $_POST['name'];
       $mailFrom = $_POST['email'];
       $Phone = $_POST['phone'];
       $Message = $_POST['message'];
       $Select = $_POST['project'];
       $mailTo = "info@amaravathiestates.in";
       $headers ="From: ".$mailFrom;$txt = "You have received an email from " .$name ".\n\n" .$Message ".\n\n" "Phone Number:" .$Phone ".\n\n" "Project Visit:" .$Select;
       mail($mailTo,$txt,$headers);
       header("Location: Contact-Us.html");
    };

1 个答案:

答案 0 :(得分:0)

您在"中忘记了$mailTo = "info@amaravat";

<?php之间不需要有空格

exit();重定向之后也要使用header,否则即使重定向发生,它下面的任何代码也会执行。(这会造成很大的安全漏洞)

代码必须为:-

<?php
if (isset($_POST['submit'])) { 
    $name = $_POST['name'];
    $mailFrom = $_POST['email'];
    $Phone = $_POST['phone'];
    $Message = $_POST['message'];
    $Select = $_POST['project'];
    $mailTo = "info@amaravat"; //forgot "
    $headers ="From: ".$mailFrom;
    $txt = "You have received an email from " .$name ".\n\n" .$Message ".\n\n" "Phone Number:" .$Phone ".\n\n" "Project Visit:" .$Select;
    mail($mailTo,$txt,$headers);
    header("Location: Contact-Us.html");
    exit(); // use exit() to stop code execution
}