Is my contact php code okay?

Associate
Joined
27 Jan 2005
Posts
830
Hello, I'm wondering if someone can be kind enough to at least give me some pointers with regards to creating a php script.

I have an xhtml page(s) that's the main contact form in which the php will get the data from, and I have a OK and failure page for after the button is pressed. I need php code to be exclusive to a php page and not mixed with the xhtml. The main css style sheet will style all webpages and the contact form in the xhtml page.

I need it to be secure and I'll try and try add recaptcha to it after.

I've looked at tecrite and phpmailer code, and seeing it has over 1,000 lines of code it kind of went way over my head.

Code:
<?php

// get posted data into local variables
$EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); 
$EmailTo = "[email protected]";
$Subject = "from web site";
$Name = Trim(stripslashes($_POST['Name'])); 
$Address = Trim(stripslashes($_POST['Address'])); 
$Telephone = Trim(stripslashes($_POST['Telephone'])); 
$message = Trim(stripslashes($_POST['message'])); 

// validation
$validationOK=true;
if (Trim($EmailFrom)=="") $validationOK=false;
if (Trim($message)=="") $validationOK=false;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=failure.htm\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Address: ";
$Body .= $Address;
$Body .= "\n";
$Body .= "Telephone: ";
$Body .= $Telephone;
$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=ok.htm\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=failure.htm\">";
}
?>
 
I've ended up using the tectite code which is doing the job. Just need to add recaptcha in to it if possible at a later date
 
Back
Top Bottom