Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

Contact Form Validation

the mail() function

Moderators: macek, egami, gesf

Contact Form Validation

Postby Sambouk » Thu Feb 28, 2013 4:16 am

Hi guys,

I'm sure this is pretty straight forward, but I have very limited PHP experience. Can someone please let me know the best way to add simple validation to the following contact form?:

Code: Select all
<?php

$EmailTo = "email@domain.com";
$Subject = "Website Contact Page";
$EmailFrom = Trim(stripslashes($_POST['Name']));

$Name = Trim(stripslashes($_POST['Name']));
$Email = Trim(stripslashes($_POST['Email']));
$Website = Trim(stripslashes($_POST['Website']));
$Message = Trim(stripslashes($_POST['Message']));

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

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$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=thanks.html\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>


Any help greatly appreciated. Thanks in advance. :D
Sambouk
New php-forum User
New php-forum User
 
Posts: 1
Joined: Thu Feb 28, 2013 4:13 am

Return to PHP coding => Mail

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.