我不知道为什么我的联系表格出现此错误,我是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");
};
答案 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
}