[Phpwm] Simple PHP Contact Form

Idvaughan at aol.com Idvaughan at aol.com
Tue Oct 13 15:43:04 UTC 2009


Hi
 
I'm just starting out using PHP and have created the following contact us  
to email web form.  I am looking for some advice and best practice  please
 
Does the form processing script  look ok and secure?
 
For example I would like to include server side validation so if a web user 
 has not completed certain fields then it would display on the form page 
that  they have not filled in the 'Name' field or entered a correct email 
address for  example.  If so what is the best way of achieving the above with my 
script  below?
 
Also I would welcome any other best practice or advice regarding the  form.
 
Many Thanks,
 
 
<?php
 
// get posted data into local variables
$EmailFrom = "_idvaughan at aol.com_ (mailto:idvaughan at aol.com) ";
$EmailTo = "_idvaughan at aol.com_ (mailto:idvaughan at aol.com) ";
$Subject =  "Enquiry";
$Name = Trim(stripslashes($_POST['Name'])); 
$Tel =  Trim(stripslashes($_POST['Tel'])); 
$email =  Trim(stripslashes($_POST['email'])); 
$message =  Trim(stripslashes($_POST['message'])); 
 
// validation
//$validationOK=true;
//if (Trim($Name)=="")  $validationOK=false;
//if (Trim($email)=="") $validationOK=false;
//if  (Trim($message)=="") $validationOK=false;
//if (!$validationOK) {
//   print "<meta http-equiv=\"refresh\"  
content=\"0;URL=contactus1.html\">";
//  exit;
//}
 
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .=  $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .=  "\n";
$Body .= "email: ";
$Body .= $email;
$Body .= "\n";
$Body .=  "message: ";
$Body .= $message;
$Body .= "\n";
 
// send email 
$success = mail($EmailTo, $Subject, $Body, "From:  <$EmailFrom>");
 
// redirect to success page 
if ($success){
print "<meta  http-equiv=\"refresh\"  content=\"0;URL=emailok.html\">";
}
else{
print "<meta  http-equiv=\"refresh\"  content=\"0;URL=contactus1.html\">";
}
?>
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.lug.org.uk/pipermail/phpwm/attachments/20091013/b66a5c78/attachment.htm 


More information about the Phpwm mailing list