I have this Contact form that works well. If someone sends me an email I get it. But for whatever reason I keep getting empty emails sent to me. Since no one could access that page im sure its not someone sending me the empty emails. I dont know what the problem is. Any help?
<form method="post" id="contactform" name="contactform" action="comment.php" id="ContactForm" name="ContactForm" method="post">
<fieldset>
<label>Email *</label>
<input class="text" type="text" name="email">
<label>Name *</label>
<input class="text" type="text" name="name" />
</fieldset>
<input class="submit-button" type="submit" name="submit" id="submit" value="Send" />
</form>
and my contact.php
<?php
$email.= "<b>Email : </b>".trim($_POST['company'])."<br/>";
$email.= "<b>Name : </b>".trim($_POST['name'])."<br/>";
//Replace [email protected] with yours, eg:[email protected]
//Both on the next line and on the mail function below.
$headers = "From: [email protected]\r\n";
$headers .= "Content-Type: text/html";
mail(
"Your Name<myname>",
"Header",
$email,
$headers
);
header("www.google.com");
?>
the "header" part in my php form is to redirec the user to a page after sending the form.
Thanks in advance.
You are probably getting visits from bots. Your script will always trigger an E-Mail, even if no POST data is present.
In your contact script, as a basic measure of protection, add something like
if ($_POST["submit"] != "Send")
die();
add further validation (as pointed out in the comments) as needed.
Might be because you don't appear to be validating the form inputs, so it can be submitted blank.
Sometimes I do this to websites (test validation, end up sending blank email), but I usually add a message later to "Validate your input!".
Excuse me if you are indeed doing validation, but that was my gut instinct because I see a lot of people fail to validate even the presence of a required input, let alone the integrity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With