考虑一下这是你的表单
<form action="yourpage.php" method="post">
<input type="text" name="name" placeholder="enter name" required>
<input type="submit" name="submit" placeholder="enter name">
确保<form action="" 链接到正确的页面并且method="post" 应该在那里。
如果当前页面上存在表单,即在我的情况下是 yourpage.php,则将表单操作留空。我还建议在输入字段末尾添加 required 例如
<input type="text" name="name" placeholder="enter your name" required>
因为它迫使用户在那里写一些值,所以你不会得到一个空值
接下来是你的 php 文件,只需在第一行添加代码
if(isset($_POST['submit'])) {
上面的代码验证用户点击了提交按钮,所以整体代码看起来像
<?php
if(isset($_POST['submit'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phoneT'];
$call = $_POST['call'];
$website = $_POST['website'];
$priority = $_POST['priority'];
$type = $_POST[itypel];
$message = $_POSTUmessagefl;
$formcontent = " From:$name \n Phone: $phone \n CallBack: $call \n Website: $website \n Priority: $priority \n Type: $type \n Message: $message";
$recipient = "YOUREMAIL@HERE.COM";
$subject - "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href=iform.htmll
style='text-decoration:none;color:#ff0099;'> Return
Home</a>";
}
?>