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

$EmailTo = "";
$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
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";

// 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\">";
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";

Any help greatly appreciated. Thanks in advance. :D
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: No registered users and 2 guests

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