Thursday, October 16, 2008

PHP form processing script

The script sends all the data filled in the form on your website to your specified email id. The good thing about the script is that you didn't have to check the field names and add individually. The script takes all the variable and send to you with the field name you had put in the form. So, it is good to put meaningful field names.



<?php

$body = "*************************************************************************\n";



foreach($_POST as $i => $value){
if($i != 'B1_x' && $i != 'B1_y'){
$body .= "$i: ".stripslashes($value)."\n";
}
}


$body.="\n";
$body.="\nUSER AGENT: ".$_SERVER['HTTP_USER_AGENT'];
$body.="\nDATE: ".date("l dS of F Y h:i:s A");
$body.="\nComment for ".$_SERVER['HTTP_REFERER'];

$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\n";
$headers .= "X-Priority: 1\n";
$headers .= "X-MSMail-Priority: High\n";
$headers .= "X-Mailer: php\n";
$headers .= "From: excelsolutions.biz <> \n";
$headers .= "Reply-To: valid_id@yourdomain.com";


if(!$form_name) $form_name = "Page Feedback";

// $to = "valid_id@yourdomainname.com";
$to = "valid_id@yourdomainname.com";
$subject = $form_name;
mail($to, $subject, $body, $headers)

?>

No comments: