我正在尝试制作一个将信息邮寄给我的表格。这是我的代码。
PHP:
$to = "mosescu_b@yahoo.com";
$subject = "Comanda de Magneti";
$name = $_POST["nume"] . $_POST["prenume"];
$email = $_POST["email"];
$phone = $_POST["telefon"];
$adress = $_POST["adresa"];
$message = <<<EMAIL
Comanda de Magneti de la $name
Adresa de E-mail este $email
Numarul de telefon este $phone
Adresa este $adress
EMAIL;
$header ="$email";
if($_POST){
mail($to, $subject, $message, $header);
$feedback = "Multumesc pentru comanda!"
}
HTML
<div class="form-group">
<form style="font-size: 1.25em; margin-left: 20px;" method="post" action="#">
<label for="nume">Nume<span style="color: red;">*</span></label> <input name="nume" id="nume" class="form-control" type="text" placeholder="Nume" title="nume">
<label for="prenume">Prenume<span style="color: red;">*</span></label> <input name="prenume" id="prenume" class="form-control" type="text" placeholder="Prenume" title="prenume">
<label for="email">E-Mail</label><span style="color: red;">*</span><input name="email" id="email" class="form-control" type="email" placeholder="E-Mail" title="email">
<label for="telefon">Numar Telefon</label><input name="telefon" id="telefon" class="form-control" type="number" placeholder="Numar Telefon" title="telefon">
<label for="adresa">Adresa</label><span style="color: red;">*</span><input name="adresa" id="adresa" class="form-control" type="text" placeholder="Strada/Numar/Localitate/Judet" title="adresa"> <br />
<input name="submit" class="btn-default" type="submit" value="Comanda!"></input>
</form>
<p id="feedback"><?php echo $feedback ?> </p>
</div>
我得到的错误是:第30行的C:\ wamp64 \ www \ Test \ comanda-magneti.php中的“解析错误:语法错误,意外'}'”
这很奇怪,因为我非常确定如果没有大括号,代码将无法正常运行。
答案 0 :(得分:2)
改变这个:
$feedback = "Multumesc pentru comanda!"
到
$feedback = "Multumesc pentru comanda!";
你忘了添加半冒号。分号是PHP中的行终止符,当然你可以跳过最后一行。但在这种情况下,你会在那之后关闭花括号。
另外请将(if _ $ POST)移至顶部,因为您在下面检查它并访问上面的POST属性。
类似于:
if(isset($_POST)){
$to = "mosescu_b@yahoo.com";
$subject = "Comanda de Magneti";
$name = (isset($_POST["nume"]) ? $_POST["nume"] : '') . isset($_POST["prenume"]) ? $_POST["prenume"] : '' ;
$email = isset($_POST["email"]) ? $_POST["email"];
$phone = isset($_POST["telefon"]) ? $_POST["telefon"] : '';
$adress = isset($_POST["adresa"]) ? $_POST["adresa"] : '';
$message = <<<EMAIL
Comanda de Magneti de la $name
Adresa de E-mail este $email
Numarul de telefon este $phone
Adresa este $adress
EMAIL;
$header ="$email";
mail($to, $subject, $message, $header);
$feedback = "Multumesc pentru comanda!"
}
如果可能的话,还要检查必要字段的POST变量。