我有这个联系表格,运作良好.如果有人给我发了一封电子邮件,我就知道了 但无论出于何种原因,我都会收到空的电子邮件发送给我.由于没有人可以访问该页面,我确定不是有人向我发送空的电子邮件.我不知道问题是什么.有帮助吗?
<form method="post" id="contactform" name="contactform" action="comment.php" id="ContactForm" name="ContactForm" method="post">
<fieldset>
<label>Email *</label>
<input class="text" type="text" name="email">
<label>Name *</label>
<input class="text" type="text" name="name" />
</fieldset>
<input class="submit-button" type="submit" name="submit" id="submit" value="Send" />
</form>
and my contact.php
<?php
$email.= "<b>Email : </b>".trim($_POST['company'])."<br/>";
$email.= "<b>Name : </b>".trim($_POST['name'])."<br/>";
//Replace YourEmailAddress@Yourdomain.com with yours, eg:contactus@mywebsite.com
//Both on the next line and on the mail function below.
$headers = "From: email@email.com\r\n";
$headers .= "Content-Type: text/html";
mail(
"Your Name<myname>",
"Header",
$email,
$headers
);
header("www.google.com");
?>
Run Code Online (Sandbox Code Playgroud)
我的php表单中的"标题"部分是在发送表单后将用户重定向到页面.
提前致谢.
你可能正在接受机器人的访问.即使没有POST数据,您的脚本也会始终触发电子邮件.
在您的联系人脚本中,作为保护的基本衡量标准,添加类似的内容
if ($_POST["submit"] != "Send")
die();
Run Code Online (Sandbox Code Playgroud)
根据需要添加进一步验证(如评论中所指出).