douwei1904 2015-08-16 11:56
浏览 50

在PHP联系表单上隐藏机器人的电子邮件地址

I've got a PHP contact form that includes the email address where the form gets emailed to hardcoded as shown below.

Is that sufficiently safe to use or am I likely to get spammed from bots?

What's a reasonable solution? Would something like this be better?

$toemail1 = "email";
$toemail = $toemail1 + "@address.com";

original php code:

    //name can contain only alpha characters and space
    if (!preg_match("/^[a-zA-Z ]+$/",$name))
    {
        $error = true;
        $name_error = "Please enter valid name";
    }
    if(!filter_var($fromemail,FILTER_VALIDATE_EMAIL))
    {
        $error = true;
        $fromemail_error = "Please enter valid email address";
    }
    if(empty($message))
    {
        $error = true;
        $message_error = "Please enter your message";
    }
    if (!$error)
    {
        //send mail
        $toemail = "email@address.com";
        $subject = "Enquiry from Visitor " . $name;
        $body = "Here goes your Message Details: 

 Name: $name 
 From: $fromemail 
 Message: 
 $message";
        $headers = "From: $fromemail
";
        $headers .= "Reply-To: $fromemail";

        if (mail ($toemail, $subject, $body, $headers))
            $alertmsg  = '<div class="alert alert-success text-center">Message sent successfully.  We will get back to you shortly!</div>';
        else
            $alertmsg = '<div class="alert alert-danger text-center">There is error in sending mail.  Please try again later.</div>';
    }
}
?>
  • 写回答

1条回答 默认 最新

  • doudao0660 2015-08-16 12:54
    关注

    PHP is processed by the server, so it's not possible to read your email, so it's not necessary to do that.

    All I can suggested is be carefully an filter your fields before to send to the PHP file, in php framework you have many functions to validate your fields but if you work directly with php you need to do that manually.

    For example:

    $email = htmlentities(substr($_POST["email"], 0, 100), ENT_QUOTES);
    

    And as I can see your do this

    filter_var($fromemail,FILTER_VALIDATE_EMAIL)
    

    It's ok too. Finally I think it's more important to work with ReCaptcha to prevent spam.

    Here you have a link:

    https://www.google.com/recaptcha/intro/index.html

    评论

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计