PHP form validation and security needed please?
Posted: Tue Apr 01, 2008 7:57 am
Hello, This is my first post here, nice to meet all of you. OK - heres my question. Here is my very simple but working php form script.
<?php
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$subject = $_POST['subject'] ;
$comments = $_POST['comments'] ;
mail( "myemail@gmail.com", "mydomain.com Formmail", "Name: $name \n\nSubject: $subject \n\nComments: $comments","From: $email" );
header( "Location: http://www.mydomain.com/thankyou.php" );
?>
It outputs this.
Name: Eric
Subject: Diabetes
Comments: So Happy!!
It took my a while to get this working so I am quite happy with it. However, I'm sure it's obvious to all of you all that I need to add some security and validation code to it. As I am completely new to php I was wondering if someone would be so kind to help me out. Thanks, take care! By the way it does not need to be anything fancy - just simple and easy for me to understand.
<?php
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$subject = $_POST['subject'] ;
$comments = $_POST['comments'] ;
mail( "myemail@gmail.com", "mydomain.com Formmail", "Name: $name \n\nSubject: $subject \n\nComments: $comments","From: $email" );
header( "Location: http://www.mydomain.com/thankyou.php" );
?>
It outputs this.
Name: Eric
Subject: Diabetes
Comments: So Happy!!
It took my a while to get this working so I am quite happy with it. However, I'm sure it's obvious to all of you all that I need to add some security and validation code to it. As I am completely new to php I was wondering if someone would be so kind to help me out. Thanks, take care! By the way it does not need to be anything fancy - just simple and easy for me to understand.