We are receiving empty emails from our site contact form, and we don't know why. Our form is very simple and the validation is also not so advanced, but enough for our purpose.
We have 5 fields:
- Name (text input)
- mail (text input)
- phone (text input)
- reason (select, 3 values)
- message (textarea)
Then with JS we validate all fields. Finally, with submit, we send the mail with php mail function:
<?php
$name = $_POST['name'];
$mail= $_POST['mail'];
$phone= $_POST['phone'];
$reason= $_POST['reason'];
$message= $_POST['message'];
$header = 'From: ' . $mail. " \r\n";
$header .= "X-Mailer: PHP/" . phpversion() . " \r\n";
$header .= "Mime-Version: 1.0 \r\n";
$header .= "Content-Type: text/plain";
$msg.= "Name: " . $name . " \r\n";
$msg.= "Mail: " . $mail. " \r\n";
$msg.= "Phone: " . $phone. " \r\n";
$msg.= "Reason: " . $reason. " \r\n";
$msg.= "Message: " . $message. " \r\n";
$for= "ourmail@ourserver.com";
$as= "Contact form";
mail($for, $as, $msg, $header);
?>
In general, works OK. But sometimes we receive an email with ALL (including reason... which is a select!) fields empty. Something like:
Subject: Contact form
Name:
Mail:
Phone:
Reason:
Message:
How can this be?