简单sendmail代码上的php语法错误

简单sendmail代码上的php语法错误,php,syntax,sendmail,Php,Syntax,Sendmail,dreamweaver告诉我第5、8、10和12行有语法错误。但我不明白为什么 <?php if(isset($_POST['submit'])) ( $msg = 'Name: ' .$_POST['FirstName'] .$_POST['LastName'] ."\n" .'Email: ' .$_POST['Email'] ."\n" .'Message: ' .$_POST['Message']; mail('email@me.com', 'M

dreamweaver告诉我第5、8、10和12行有语法错误。但我不明白为什么

<?php
if(isset($_POST['submit'])) (
    $msg = 'Name: ' .$_POST['FirstName'] .$_POST['LastName'] ."\n" 
    .'Email: ' .$_POST['Email'] ."\n" 
    .'Message: ' .$_POST['Message'];
    mail('email@me.com', 'Message from website', $msg);
    header('location: contact-thank-you.php');
)
else (
header('location: contact.php');
exit(0);
)
)       
?>
使用:

将代码更改为

if(isset($_POST['submit'])) {
    $msg = 'Name: ' .$_POST['FirstName'] .$_POST['LastName'] ."\n" 
    .'Email: ' .$_POST['Email'] ."\n" 
    .'Message: ' .$_POST['Message'];
    mail('email@me.com', 'Message from website', $msg);
    header('location: contact-thank-you.php');
}
else {
header('location: contact.php');
exit(0);
}

您需要使用
{
}
而不是
&

检查firstname和lastname之间的连接字符串。我想这个错误存在于字符串连接中。试着做“名字:”$_POST['firstname']。“”.$\u POST['lasname']。“\n”。。。。 您已经用两个不同的引号组成了字符串,以便在一个位置形成一个字符串。您正在使用单引号,并且正在使用双引号。请尝试清除它。始终使用一致的引号,并且在字符串连接中使用双引号始终是一个好主意。它实际上提高了代码的可读性


希望这有助于运行代码,并查看PHP是否对此有所抱怨。您使用的是
而不是花括号。对问题的解释会有所帮助,而不是找出区别。
if(isset($_POST['submit'])) {
    $msg = 'Name: ' .$_POST['FirstName'] .$_POST['LastName'] ."\n" 
    .'Email: ' .$_POST['Email'] ."\n" 
    .'Message: ' .$_POST['Message'];
    mail('email@me.com', 'Message from website', $msg);
    header('location: contact-thank-you.php');
}
else {
header('location: contact.php');
exit(0);
}