我已经为我的一个客户在 php 中编写了联系我们表格及其流程页面
当用户提交表单时,会生成邮件并将其重定向到我的客户收件箱
一天结束时,我收到了数百封可怕的未知垃圾邮件,我不知道它是从哪里生成的,
因此,我们的网站有被加入谷歌和其他搜索引擎的黑名单的危险
谁能给我一个阻止这些垃圾邮件的解决方案,还请找到我的 php 邮件代码的附件
下面是我的php代码
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$email = $_POST["email"];
$to = "test@myaddress.com";
$cname = htmlentities(ucfirst($_POST['name']));
$subject = "Subject Comes here";
$body= "Name : ";
$body.= $cname;
$body .= "\nE-mail : ";
$body .= htmlentities($_POST['email']);
$body.= "\nMessage : ";
$body.= htmlentities($_POST['message']);
function is_valid_email($email)
{
return preg_match('#^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~]+@([0-9.]+|([^\s]+\.+[a-z]{2,6}))$#si', $email);
}
function contains_bad_str($str_to_test) {
$bad_strings = array(
"content-type:"
,"mime-version:"
,"multipart/mixed"
,"Content-Transfer-Encoding:"
,"bcc:"
,"cc:"
,"to:"
);
foreach($bad_strings as $bad_string) {
if(eregi($bad_string, strtolower($str_to_test))) {
header('Location: status.php?status=failed');
}
}
}
function contains_newlines($str_to_test) {
if(preg_match("/(%0A|%0D|\\n+|\\r+)/i", $str_to_test) != 0) {
header('Location: status.php?status=failed');
}
}
if (!is_valid_email($email)) {
header('Location: status.php?status=failed');
}
contains_bad_str($email);
contains_bad_str($subject);
contains_bad_str(body);
contains_newlines($email);
contains_newlines($subject);
$headers = "From: $email";
mail($to, $subject, $body, $headers);
header('Location: status.php?status=success');
}
?>