The google web crawler keeps triggering the form on my website, how can I stop these blank emails?

I've checked the latest visitor stats on my website against the times of these blank contact form emails and found out that the ip is google's.
So then I visited my php file and noticed that it triggers an email with a blank form to be sent to me just like when the google crawler visits it.

The way its set up is there is a contact.htm page with the form and its linked to a php page that handles the form.

I already have a javascript file that prevents the form from being sent if the fields are not filled out, but that doesnt stop it from being sent when the crawler (or anyone) actually goes directly to the php page that handles the contact form, and thats how I keep receiving these blank form emails, from the crawler visiting the php page directly.

What can I do about this?

    dont rely on javascript, yo need the form handling page to check its been submitted to before sending an email

    if($_POST[submit]) or what ever is appropriate in your case.

      You're dealing with a beginner here, I am still learning.
      Below is the php which handles my form, my friend helped me with it,
      but she isn't available to help me now, thats why I am posting here.
      Can you tell me what I should change in order to stop an email being
      sent everytime a crawler visits the page?
      Thank you!!!

      <?php
      
      $name = trim(htmlentities($_POST['name'],ENT_QUOTES,'utf-8'));
      
      $company = trim(htmlentities($_POST['company'],ENT_QUOTES,'utf-8'));
      
      $email = trim(htmlentities($_POST['email'],ENT_QUOTES,'utf-8'));
      
      $phone = trim(htmlentities($_POST['phone'],ENT_QUOTES,'utf-8'));
      
      $interest = trim(htmlentities($_POST['interest'],ENT_QUOTES,'utf-8'));
      
      $comments = trim(htmlentities($_POST['comments'],ENT_QUOTES,'utf-8'));
      
      
      $to = "me@mysite.com";
      
      $subject = "Visitor Contact";
      
      $message = "Name: ".$name;
      
      $message.="\n\nCompany: ".$company;
      
      $message.="\n\nEmail: ".$email;
      
      $message.="\n\nPhone: ".$phone;
      
      $message.="\n\nInterest: ".$interest;
      
      $message .= "\n\nMessage: ".$comments;
      
      $headers = "From: $email";
      
      $headers .="\nReply-To: $email";
      
      $success = mail($to, $subject, $message, $headers);
      
      
      if ($success) {
      
      print ("<b>Thank you $name. You'll be hearing from us soon.</b>");
      
      } else {
      
      print ("<b>I'm sorry, there was a technical glitch, please send your email to me@gmysite.com directly.</b>");
      
      }
      
      ?>

        Hi

        How does that work dagon as I use javascript, and I validate the php script for the submit as in

        if (isset($_POST['Submit_message']) && ($_POST['Submit_message'] == "Send Message")) {...

        plus empty fields yet I have occasionally still got forms submitted by robots? I was thinking of using the process of making users enter a code (capture??) but I believe that this is not fool proof either?

        Cheers

          This topic was solved at another forum with a minor code adjustment to check the fields before sending. Here is the adjusted code, look above the "$to = " line and also at the very end of the code at the bottom to see the changes:

          <?php
          
          $name = trim(htmlentities($_POST['name'],ENT_QUOTES,'utf-8'));
          
          $company = trim(htmlentities($_POST['company'],ENT_QUOTES,'utf-8'));
          
          $email = trim(htmlentities($_POST['email'],ENT_QUOTES,'utf-8'));
          
          $phone = trim(htmlentities($_POST['phone'],ENT_QUOTES,'utf-8'));
          
          $interest = trim(htmlentities($_POST['interest'],ENT_QUOTES,'utf-8'));
          
          $comments = trim(htmlentities($_POST['comments'],ENT_QUOTES,'utf-8'));
          
          if($name != '' && $company != '' && $email != '' && $phone != ''){
          
          $to = "me@mysite.com";
          
          $subject = "Visitor Contact";
          
          $message = "Name: ".$name;
          
          $message.="\n\nCompany: ".$company;
          
          $message.="\n\nEmail: ".$email;
          
          $message.="\n\nPhone: ".$phone;
          
          $message.="\n\nInterest: ".$interest;
          
          $message .= "\n\nMessage: ".$comments;
          
          $headers = "From: $email";
          
          $headers .="\nReply-To: $email";
          
          $success = mail($to, $subject, $message, $headers);
          
          
          if ($success) {
          
          print ("<b>Thank you $name. You'll be hearing from us soon.</b>");
          
          } else {
          
          print ("<b>I'm sorry, there was a technical glitch, please send your email to [email]me@gmysite.com[/email] directly.</b>");
          
          }
          }
          else
          {
          echo "Please fill the required fields, thankyou";
          }
          
          ?>

          and here is another solution that may be better or worse, however, I have not tested this one yet:

          <?php
          
          $name = trim(htmlentities($_POST['name'],ENT_QUOTES,'utf-8'));
          
          $company = trim(htmlentities($_POST['company'],ENT_QUOTES,'utf-8'));
          
          $email = trim(htmlentities($_POST['email'],ENT_QUOTES,'utf-8'));
          
          $phone = trim(htmlentities($_POST['phone'],ENT_QUOTES,'utf-8'));
          
          $interest = trim(htmlentities($_POST['interest'],ENT_QUOTES,'utf-8'));
          
          $comments = trim(htmlentities($_POST['comments'],ENT_QUOTES,'utf-8'));
          
          if (strlen($name) == 0 )
          {
          die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please Go back  fill out the required fields</font></p>");
          }
          
          if (strlen($company) == 0 )
          {
          die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please Go back  fill out the required fields</font></p>");
          }
          
          if (strlen($email) == 0 )
          {
          die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please Go back  fill out the required fields</font></p>");
          }
          
          if (strlen($phone) == 0 )
          {
          die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please Go back  fill out the required fields</font></p>");
          }
          
          $to = "me@mysite.com";
          
          $subject = "Visitor Contact";
          
          $message = "Name: ".$name;
          
          $message.="\n\nCompany: ".$company;
          
          $message.="\n\nEmail: ".$email;
          
          $message.="\n\nPhone: ".$phone;
          
          $message.="\n\nInterest: ".$interest;
          
          $message .= "\n\nMessage: ".$comments;
          
          $headers = "From: $email";
          
          $headers .="\nReply-To: $email";
          
          $success = mail($to, $subject, $message, $headers);
          
          
          if ($success) {
          
          print ("<b>Thank you $name. You'll be hearing from us soon.</b>");
          
          } else {
          
          print ("<b>I'm sorry, there was a technical glitch, please send your email to me@gmysite.com directly.</b>");
          
          }
          
          ?>
            Write a Reply...