Reputation: 1449
I am having some issues with a client receiving blank forms through my email.
I am using the following form
<form method="get" action="javascript:contactForm()" class="form">
<div class="alertForm"><!-- Error's go in here --></div>
<div class="innerForm">
<div class="placeholder">Your Name</div>
<input type="text" name="name" value="" id="name" placeholder="">
<div class="placeholder">Your Phone Number</div>
<input type="text" name="number" value="" id="number" placeholder="">
<select name="time" id="time">
<option value="null">Please Select A Time</option>
<option value="09:00 - 11:00">09:00 - 11:00</option>
<option value="11:00 - 13:00">11:00 - 13:00</option>
<option value="13:00 - 15:00">13:00 - 15:00</option>
<option value="15:00 - 17:00">15:00 - 17:00</option>
<option value="17:00 - 19:00">17:00 - 19:00</option>
</select>
<input type="submit" value="Call Me Back">
</div>
</form>
And the PHP post
$name = $_POST['name']; $number = $_POST['number']; $time = $_POST['time'];
$subject = "[CALLBACK] ".$name." - ".$number;
$to = "[email protected]";
$headers = "From:" . "[email protected]";
$message = $name." would like you to call them back on ".$number." between ".$time;
if(mail($to, $subject, $message, $headers)){ echo "We will call you within the time you've selected. If not today, then the next day.<br><br>Thank you."; }
else{ echo "Something's gone horribly wrong! PANIC."; }
If i try it it seems wo to work fine - however i am receiving about 7 blank emails per day. I am unsure if these are SPAM or they are actually contact forms however have lost their data?
Any help will be greatly appreciated.
Upvotes: 1
Views: 1691
Reputation: 5454
Your form method
is set to get
but you're trying to access $_POST
variables in your PHP. Switch your form to method="post"
or use $_GET
instead of $_POST
(though I'd recommend using POST).
But, your should also add some server-side validation to your form. At least check that something has been entered into your form fields.
Upvotes: 2