php联系表格编码问题

时间:2017-07-13 20:41:57

标签: php forms parentheses

我正在尝试为现有的html表单创建php代码。当我尝试创建代码时,它似乎有关闭括号的问题,任何人都可以帮忙吗?

<?php

if (isset($_POST['your_name'])) {
$your_name = $_POST['your_name'];

if (isset($_POST['your_email'])) {
$your_email = $_POST['your_email'];

if (isset($_POST['subject'])) ;
$subject = $_POST['subject'];

if (isset($_POST['message'])) ;
$message = $_POST['message'];

$to = "email.co.uk";
$subject = "New Message";

mail ($to, $subject, $message, "From: " . $your_name);
echo "Your message has been sent";

?>

由于

1 个答案:

答案 0 :(得分:-1)

这是因为您在每个;语句中使用if而不是if { .. }语句尝试此代码

<?php

if (isset($_POST['your_name'])) {
$your_name = $_POST['your_name'];
} 

if (isset($_POST['your_email'])) {
$your_email = $_POST['your_email'];
}

if (isset($_POST['subject'])) {
$subject = $_POST['subject'];
}

if (isset($_POST['message'])) {
$message = $_POST['message'];
}

$to = "email.co.uk";
$subject = "New Message";

mail ($to, $subject, $message, "From: " . $your_name);
echo "Your message has been sent";

?>