Associate
- Joined
- 2 Nov 2007
- Posts
- 488
This is driving me nuts. I would really appreciate some help before i pull my hair out. The bit that seems to be causing all the issues is:
I cant see where the error is being set though?!
Full Code:
Cheers
Code:
if(!isset($error)) {
I cant see where the error is being set though?!
Full Code:
Code:
//If the form is submitted
if(isset($_POST['submit'])) {
//Start the session
session_start();
//Set blacklists
$badwords = "/(adult|beastial|bestial|blowjob|clit|cum|cunilingus|cunillingus|cunnilingus|****|ejaculate|felatio|fellatio|****|***|fuks|gangbang|gangbanged|gangbangs|hotsex|hardcode|jism|jiz|orgasim|orgasims|orgasm|orgasms|phonesex|phuk|phuq|porn|pussies|pussy|*****|xxx|viagra|phentermine|tramadol|adipex|advai|alprazolam|ambien|ambian|amoxicillin|antivert|blackjack|backgammon|texas|holdem|poker|carisoprodol|ciara|ciprofloxacin|debt|dating|porn|voyeur)/i";
$exploits = "/(content-type|bcc:|cc:|document.cookie|onclick|onload|javascript)/i";
$bots = "/(Indy|Blaiz|Java|libwww-perl|Python|OutfoxBot|User-Agent|PycURL|AlphaServer|T8Abot|Syntryx|WinHttp|WebBandit|nicebot)/i";
//Check for any bots
if(preg_match($bots, $_SERVER['HTTP_USER_AGENT'])) {
die("<p>Spam bots are not allowed.</p>");
}
//Check to make sure that the name field is not empty, and that it does not contain badwords or exploits
if(trim($_POST['contactname']) == '' ) {
$error['contactname'] = "- You didn't enter your Full Name.<br>";
} else if (preg_match($badwords, trim($_POST['contactname'])) !== 0 || preg_match($exploits, trim($_POST['contactname'])) !== 0) {
$error['contactname'] = "- You entered a Full Name which contains unacceptable words.<br>";
} else {
$name = trim(stripslashes(strip_tags($_POST['contactname'])));
$error['contactname'] = NULL;
}
//Check to make sure sure that a valid email address is submitted
if(trim($_POST['email']) == '') {
$error['email'] = "- You didn't enter your Email address.<br>";
} else if (!preg_match('/([a-z0-9])([-a-z0-9._])+([a-z0-9])\@([a-z0-9])([-a-z0-9_])+([a-z0-9])(\.([a-z0-9])([-a-z0-9_-])([a-z0-9])+)*/i', trim($_POST['email'])) || preg_match($badwords, trim($_POST['email'])) !== 0 || preg_match($exploits, trim($_POST['email'])) !== 0) {
$error['email'] = "- You didn't enter a valid Email address.<br>";
} else {
$email = trim(stripslashes(strip_tags($_POST['email'])));
$error['email'] = NULL;
}
//Check to make sure that the telephone number field is not empty
if(trim($_POST['telephone']) == '') {
$error['telephone'] = "- You did not enter your Telephone Number.<br>";
} else if (preg_match($badwords, trim($_POST['telephone'])) !== 0 || preg_match($exploits, trim($_POST['telephone'])) !== 0) {
$error['telephone'] = "- You entered a Telephone Number which is not valid.<br>";
} else {
$telephone = trim(stripslashes(strip_tags($_POST['telephone'])));
$error['telephone'] = NULL;
}
//Check to make sure comments were entered
if(trim($_POST['message']) == '') {
$error['message'] = "- You didn't enter a Message.<br>";
} else if (preg_match($badwords, trim($_POST['message'])) !== 0 || preg_match($exploits, trim($_POST['message'])) !== 0) {
$error['message'] = "- You entered a Message which contains unacceptable words.<br>";
} else {
$comments = trim(stripslashes(strip_tags($_POST['message'])));
$error['message'] = NULL;
}
//Check if there are any errors
if (!isset($error['contactname']) && !isset($error['email']) && !isset($error['telephone']) && !isset($error['message'])) {
$error = NULL;
}
//If there is no error, send the email
if(!isset($error)) {
//Recipient email address
$emailRecipient = '***@gmail.com';
$emailTo = 'Company <'.$emailRecipient.'>';
//Email subject
$emailSubject = 'Enquiry';
//Date
date_default_timezone_set('Europe/London');
$date = date('l, d F Y \a\t g:i A', time());
//Customer callback?
if ($_POST['checkbox'] == "1") {
$requestCall = 'Yes';
} else {
$requestCall = 'No';
}
$callBack = 'Customer requests a call back? <strong>'.$requestCall.'</strong>';
//Message
$body = '
<html>
<head>
<title>Enquiry</title>
<style type="text/css">
body {
font-family:"Trebuchet MS", Tahoma, Verdana, Arial, Helvetica, sans-serif;
color:#333;
}
h1 {
text-align:center;
font-weight:bold;
}
</style>
</head>
<body>
<h1><b>Attention</b></h1>
<p>You have received an enquiry, below, through your website contact form. The message was sent: <i>'.$date.'</i></p>
<p>Name: <i>'.$name.'</i></p>
<p>Email: <i>'.$email.'</i></p>
<p>Telephone Number: <i>'.$telephone.'</i></p>
<p>Comments:<br><i>'.$comments.'</i></p>
<p>Call Back: <i>'.$callBack.'</i></p>
</body>
</html>
';
//To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
//Additional headers
$headers .= 'From: Thompson\'s East Africa Website <'.$emailRecipient.'>' . "\r\n";
$headers .= 'Reply-To: '.$name.' <'.$email.'>' . "\r\n";
$headers .= 'Return-Path: '.$name.' <'.$email.'>' . "\r\n";
$headers .= 'X-Mailer: PHP/'.phpversion().'' . "\r\n";
$headers .= 'X-Sender: '.$emailRecipient.'' . "\r\n";
//reCaptcha
require_once('recaptchalib.php');
$privatekey = "**************";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
die ("The reCAPTCHA wasn't entered correctly. <a href =\"javascript:history.back()\">Please go back and try it again.</a>"
);
}
//Send the message
mail($emailTo, $emailSubject, $body, $headers);
$emailSent = true;
}
elseif (!is_null($error))
{ echo "Error is null";
}
}
?>
Cheers