【问题标题】:How to block spam mails in inbox using php如何使用php阻止收件箱中的垃圾邮件
【发布时间】:2013-08-01 22:52:22
【问题描述】:

我已经用 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');
}
?>

【问题讨论】:

标签: php security email-spam


【解决方案1】:

或使用应保持为空的隐藏字段。垃圾邮件机器人有填写所有输入字段的习惯。

更多关于这里: How to prevent robots from automatically filling up a form?

【讨论】:

    【解决方案2】:

    使用验证码来防止垃圾邮件机器人滥用您的联系表单,并确保只有人类才能使用它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-31
      • 1970-01-01
      相关资源
      最近更新 更多