为什么输出显示“未定义”;提交;在php中?

为什么输出显示“未定义”;提交;在php中?,php,html,Php,Html,实际上,我正在创建一个简单的表单来向我的电子邮件ID发送邮件。 这是我的密码: <!doctype html> <html> <body> <form> <input type='text' name='name'> <input type='email' name="email"> <input typ

实际上,我正在创建一个简单的表单来向我的电子邮件ID发送邮件。 这是我的密码:

<!doctype html>
<html>
    <body>
        <form>
            <input type='text' name='name'>
            <input type='email' name="email">
            <input type="number" name="mobile">
            <input type="text" name="message">
            <input type="submit" name='submit'>
        </form> 
    </body>
</html>

php代码:

<?php
if($_POST['submit']!="")
{
 $cname = $_POST['name'];

 $email = $_POST['email'];
 $mob = $_POST['mobile'];
 $query = $_POST['message'];
 $subject="Enquiry";
 $message="Name : $cname \n  email : $email \n  Message : $query \n";
 $email_from = '<name@gmail.com.com>';
 $subject = "registration";
 $message = "You have received a new message from the user <b> $cname. </b> \n". "Here is the message:\n $message".
 $to = "name<name@gmail.com>";
 $headers = "From: $email_from \r\n";
 $headers.= "Reply-To: $email \r\n";
    if(mail($to, $subject, $message, $headers))
    {
     echo "<script>alert('Dear User, You Are Successfully Registered')</script>";
    }
}
?>

如果加载页面,
$\u POST
为空,
$\u POST[“提交”]
未定义。如果单击“提交”按钮,将设置
$\u POST[“提交”]
。因此,与其检查
$\u POST[“submit”]
的内容是否为空字符串,不如检查变量是否已设置:

if( isset($_POST["submit]) ){
   // Form submitted, continue
}
此外,您忘记在表单中设置方法:

<form method="post">

您需要的是POST数据,但没有发送。-如果不指定方法,它将是
$\u GET