简体   繁体   中英

php mail form sends false mails

I'm new to php and I have a form that needs to get information and send it to me by mail. The problem is that sometimes I receive email containing only an IP adress and nothing else. I tried pressing "send" without entering anything in the fields and I receive an email containing everything else but the answers to the questions, so that is not the case it seems. My questions is why do I receive email containing only an IP adress? Thanks!

<?php
    $to = "mail@gmail.com";
    $subject = "energiebio contact form: {$_POST['ams']['Destination']} ";
    $from = $_POST['ams']['E-mail'];
    $valid=1;
    $message ='';

    foreach ($_POST['mas'] as $k=>$v){
        if (trim($v)=='')$valid=0;
        $k = str_replace('_',' ',$k);
        $message .="$k : $v<br>";
    }

    $message .="<hr />IP: {$_SERVER['REMOTE_ADDR']}";

    function sndmail($from,$to,$subject,$message){
        $headers = "MIME-Version: 1.0\r\n";
        $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
        $headers .= "From:".$from ."\r\n";
        mail($to, $subject, $message, $headers);
    }

    if ($valid=='1') {
        sndmail($from,$to,$subject,$message);
        header( 'Location: http://site.ro/danke.html' ) ;
    }else header( 'Location: http://site.ro/error.html' ) ;
?>

I've discovered that it's the same IP and that I can't get a "whois" on it the same: 92.85.174.105

I'd say something, for example google bot or a spam bot, is hitting your email script without using your form. If you have HTML like this:

<form action="postmail.php">
<!-- stuff -->

a script can just hit your "postmail.php" without using the send button. Then body content would be empty, and you'd get an empty email containing nothing but the senders ip.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM