zero-perfoliate
zero-perfoliate

Author Topic: I have a contact form on my site...keep getting blank emails, how do I stop it?  (Read 1564 times)

Offline The_Lorax

  • New PHP Members
  • Posts: 2
  • Karma: +0/-0
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?

Here is the code from the php file that handles the form....


Code: [Select]
<?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>");

}

?>

icestormz

  • Guest
Hi please give this code a try and get back to me all i added was php validation to check if the field was left blank or not if it is left blank it will echo a message telling them to back and fill it out.

Code: [Select]
<?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) == )
{
die(
"<p align='center'><font face='Arial' size='3' color='#FF0000'>Please Go back  fill out the required fields</font></p>");
}

if (
strlen($company) == )
{
die(
"<p align='center'><font face='Arial' size='3' color='#FF0000'>Please Go back  fill out the required fields</font></p>");
}

if (
strlen($email) == )
{
die(
"<p align='center'><font face='Arial' size='3' color='#FF0000'>Please Go back  fill out the required fields</font></p>");
}

if (
strlen($phone) == )
{
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>");

}

?>

Offline The_Lorax

  • New PHP Members
  • Posts: 2
  • Karma: +0/-0
Hi thank you for your help, I am going to examine your code and test it, but earlier today I got another solution,
here it is:

Code: [Select]
<?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 me@gmysite.com directly.</b>");

}
}
else
{
echo 
"Please fill the required fields, thankyou";
}

?>

This seems to work so I am using this, but maybe after I look at it closer, I like yours better?
Anyway, I am learning and that is good.

Thank you!

icestormz

  • Guest
Yes its pretty much the same thing, except my code lets you deliver different messages when the error happens but glad you figured it out us know if you need anything else don't hesitate to post

Offline R4nk3d

  • PHP Workers
  • **
  • Posts: 8
  • Karma: +0/-0
question for me here, would u be able to make:
robot.txt
and type
disallow: /form

/form being w/e directory u wanted google and other search engines not to find/give out.

icestormz

  • Guest
yes you can your robot.txt should look like this

Code: [Select]
# addresses all robots by using wild card *
User-agent: *

# list folders robots are not allowed to index, if you have a sub folder within this
# directory make sure to also include it using Disallow: /form/subfoldersname/

Disallow: /form/


# list specific files robots are not allowed to index

Disallow: /form/form.php

 

zero-perfoliate