这是我的 HTML 表单
<form method="post" name="myemailform" action="form-to-email.php">
<p>
<label for='name'>Enter Name: </label><br>
<input type="text" name="name">
</p>
<p>
<label for='email'>Enter Email Address:</label><br>
<input type="text" name="email">
</p>
<p>
<label for='message'>Enter Message:</label> <br>
<textarea name="message"></textarea>
</p>
<input type="submit" name='submit' value="submit">
</form>
这是 PHP 邮件代码,当用户点击提交时获取数据
<?php
if(!isset($_POST['submit']))
{
echo "error; you need to submit the form!";
}
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
//Validate first
if(empty($name)||empty($visitor_email))
{
echo "Name and email are mandatory!";
exit;
}
$email_from = 'tom@amazing-designs.com';//<== update the email address
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n".
"Here is the message:\n $message".
$to = "khan.koder@gmail.com";//<== update the email address
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: thank-you.html');
?>
它没有显示错误,但只是登陆页面thank-you.html 我检查了我的电子邮件帐户但没有收到邮件
请帮忙看看有什么问题