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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog