【发布时间】:2015-08-01 13:48:24
【问题描述】:
您好,我已经在我的网站上制作了联系表,但即使用户没有输入任何详细信息并按下提交按钮,它也会向我发送一封空白电子邮件,其中没有来自未知发件人的任何内容。
有人知道为什么会这样吗?我已经添加了表单验证,所以它不应该发送任何东西。
HTML 代码:
<form action="mail.php" method="POST">
<font color="red">*</font> Name <input type="text" name="name" required>
<font color="red">*</font> Phone <input type="text" name="phone" required>
<font color="red">*</font> Email <input type="text" name="email" required>
<font color="red">*</font> Message <input type="text" name="message" placeholder="I am looking for..." required><br />
<input type="image" src="images/Landing_Pages/submit.png" border="0" alt="Submit" />
</form>
PHP 代码:
<?php $name = $_POST['name'];
$phone = $_POST['phone'];
$preferred = $_POST['preferred'];
$email = $_POST['email'];
$formcontent="From: $name \n Phone: $phone \n Email: $email \n Message: $message \n Preferred Contact: $preferred \n Email: $email";
$recipient = "bwebb@webbmaster.com.au";
$subject = "New Request Southbank";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
?>
【问题讨论】:
-
您需要对所有输入使用条件语句
!empty()。有人没有填写一个或多个字段。 -
您的代码中缺少
$message=$_POST['message']!!! -
我是否只需将该代码添加到每个输入字段中?
-
“我已经添加了表单验证,所以它不应该发送任何东西。” - 哦,在哪里?
-
似乎你没有关注 cmets,或者只是懒得回答他们,^^^ 反正上面那个。这告诉我你没有向我们展示你所说的“验证”的完整代码。