PHP Contact Form Validation - HELP!

Copy link to clipboard
Copied
Hello,
I've created my contact page on my website but I'm not happy with the validation and im getting emails through which are empty and with no contact details??
Could someone please help me!
This is my php code which is linked to my html page
<?php
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
mail( "contactus@mammothdesignstudios.com", "MDS2010 Enquiry",
$message, "From: $email" );
header( "Location: http://www.mammothdesignstudios.com/thanks.html" );
?>
I have just used spry for validation but realise this is not the best way to go.
Could someone view my code www.mammothdesignstudios.com/contact_us.html
I'd really appreciate someones help on this,
Thank you!

Copy link to clipboard
Copied
You can create a simple validation as below:
$error = array();
if (empty($_REQUEST['email'])) {
$error[] = "The email is empty";
}
.... add any other validations u want.
Then add this
//check no errors
if(!$error) {
mail( "contactus@mammothdesignstudios.com", "MDS2010 Enquiry", $message, "From: $email" );
}
Thus will prevent email to be send if there's any error occurs.
On html page u can add this if u want.
<p>
<?php if ($error) {
echo '<ul>';
foreach ($error as $alert) {
echo "<li>$alert</li>\n";
}
echo '</ul>';
} ?>
</p>

Copy link to clipboard
Copied
Hi, thanks for the reply, but I was hoping to keep the same effect I currently have with the validation I have in place.
But im not sure if my current validation is working fine or not, as I keep receiving blank emails from (unkown) but with the MDS2010 Enquiry title. But if I try to send an empty contact form from my site it wont let me as the validation seems to work as it asks for email, name etc.
If i fill it out correctly, I recieve an email which is perfectly fine. So what I dont understand is how am i getting the blank emails??
I'd really like to know whats going on because at the moment im not sure whether some ones requesting something or whether its something else???
Any ideas, please...

Copy link to clipboard
Copied
sorry posted twice

