}
function validate_form($VARS)
{
$blanks['First Name'] = trim($VARS['firstname']);
$blanks['Last Name'] = trim($VARS['lastname']);
$blanks['Subject'] = trim($VARS['subject']);
$comments = trim($VARS['comments']);
$email = trim($VARS['email']);
//Check for blanks
foreach ($blanks as $key => $value)
{
if(!$value)
{
$error_messages[$key] = 'is empty or invalid';
}
}
//Validate the comments for possible email injection
$prohibited = array //contains phrases that should be filtered - case insensitive
(
"bcc:" //the biggies first
,"cc:"
,"reply-to"
,"mime-version" //some other common ones
,"multipart/mixed"
,"multipart/alternative"
,"multipart/related"
,"boundary="
,"charset"
,"content-disposition"
,"content-type"
,"content-transfer-encoding"
,"errors-to" // more arcane but still dangerous and shouldn't be there
,"apparently-to"
,"in-reply-to"
,"message-id"
,"x-mailer"
,"x-sender"
,"x-uidl"
);
foreach($prohibited as $dangerous)
{
if(eregi($dangerous, strtolower($comments)))
{
$error_messages['Comments'] = 'Your response contains text that is potentially harmful to this server. Your response has not been sent! Please try rephrasing your response. We apologise for any inconvenience.';
break;
}
}
//Check for a valid contact email address
if( !eregi("@", $email) )
{
$error_messages['Email'] = 'please enter a valid email address';
}
else
{
//check for email injection
$prohibited = array //contains phrases that should be filtered - case insensitive
(
"\r"
,"\n"
,"0x0A"
,"%0A"
,"0x0D"
,"%0D"
,"%0A%0D"
);
foreach($prohibited as $dangerous)
{
if(eregi($dangerous, strtolower($email)))
{
$error_messages['Email'] = 'please enter a valid email address';
break;
}
}
}
return $error_messages;
}
function clean_var($var)
{
//check for email injection
$prohibited = array //contains phrases that should be filtered - case insensitive
(
"\r"
,"\n"
,"0x0A"
,"%0A"
,"0x0D"
,"%0D"
,"%0A%0D"
);
$var = trim($var);
foreach($prohibited as $dangerous)
{
$var = eregi_replace($dangerous, '', strtolower($var));
}
return $var;
}
function send_email($VARS)
{
global $sitename;
//'To' email address(our address to recieve the emails from the web)
$email = "ircontact@capworth.com";
//$email = "simon@clickheremedia.com";
//***Setting up the mail variables:
//Sender's email address (the email address of the user submitting the form)
$sender = 'contactform@mi3cap.com';
//Subject of the email
$subject = $sitename . " Contact Form: ". $VARS['subject'];
//Constructing Body of the email
$body .= $sitename . " Contact Form has submitted the following information:\r\n";
$body .= "First Name: ". clean_var($VARS['firstname']) ."\r\n";
$body .= "Last Name: ". clean_var($VARS['lastname']) ."\r\n";
$body .= "Company: ". clean_var($VARS['company']) ."\r\n";
$body .= "Email: ". clean_var($VARS['email']) ."\r\n";
$body .= "Subject: ". clean_var($VARS['subject']) ."\r\n";
$body .= "Comments: ". trim($VARS['comments']) ."\r\n";
$body = trim(stripslashes($body));
//Additional headers for the email
$headers .= "From: $sender <$sender>\r\n";
$headers .= "Return-Path: <$sender>\r\n";
//Mail the email
@mail($email, $subject, $body, $headers);
$headers="";
}
function confirm()
{
?>
Your comments/message has been sent successfully. Please allow 24/48 hours processing time.