There was a } missing in the code I posted here. Sorry about that.
PHP Code:
<?php
// function by Andrew Krespanis
function isInjection($text) {
$text = strtolower($text);
if (preg_match('#(content\s*-\s*disposition)|(bcc\:)|(cc\:)|(content\s*-\s*transfer\s*-\s*encoding)|(mime\s*-\s*version)|(multipart\s*/\s*mixed)|(multipart\s*/\s*alternative)|(multipart\s*/\s*related)|(reply\s*-\s*to)|(x\s*-\s*mailer)|(x\s*-\s*sender)|(x\s*-\s*uidl)#is',$text))
{ return true; }
else
{ return false;}
}
// declare an empty error array
$error_message = array();
// if form submitted
if (isset($_POST['SUBMIT']))
{
if (get_magic_quotes_gpc())
{
foreach ($_POST as $key => $value)
{
$temp = stripslashes($value);
$_POST[$key] = $temp;
}
}
// function by praetor
if (!preg_match('/^[a-zA-Z\._\-0-9]+?@[a-zA-Z\._\-0-9]+?\.[a-zA-Z\._\-0-9]{2,3}$/',$_POST['email']))
{
$error_message[] = 'Invalid email!';
}
if(($_POST['fullname'] == '') || ($_POST['tel'] == ''))
{
$error_message[] = '<strong>Sorry</strong>, You seem to have missed out some required fields:';
}
if($_POST['fullname'] == '')
{
$error_message[] = ' <br /><strong>Full Name</strong> is a required Field';
}
if($_POST['tel'] == '')
{
$error_message[] = ' <br /><strong>Telephone</strong> is a required Field';
}
// is there any email injection attempt?
if( isInjection($_POST['fullname']) || isInjection($_POST['tel']) || isInjection($_POST['email']) || isInjection($_POST['message'])) {
$error_message[] = "There seems to be a problem with the data you entered, please try again.";
}
// if there are no errors continue
if(count($error_message) ==0)
{
// proceed to mail()
$to = 'info@mydomian.co.ukk';
$subject = 'Website form';
// message goes here
$message = "Full Name: " . $_POST['fullname'] . "\n";
$message .= "Telephone: " . $_POST['tel'] . "\n";
$message .= "Email: " . $_POST['email'] . "\n";
$message .= "Message: " . $_POST['message'] . "\n";
// headers go here
$headers = "From: " . $_POST['email'] . "\n";
$headers .= "Content-type: text/plain; charset=UTF-8";
$sent = mail($to, $subject, $message, $headers);
//$autorespond = mail($_POST['email'], "Form Auto Response.", "Thank you for contacting Me, your message has been received and we will contact you shortly.", "From: info@mydomian.co.ukk<info@mydomian.co.ukk>");
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title></title>
</head>
<body>
<p>test</p>
<?php
if (isset($sent))
{
echo '<p><span class="thanks"><strong>Thank you</strong> for contacting Tablets of Stone.</span></p>';
}
if (isset($error_message))
{
echo '<p class="sorry">';
foreach ($error_message as $key => $value)
{
echo "$value" . '<br />';
}
echo '</p>';
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset>
<legend>Feedback Form</legend>
<div class="row">
<span class="formLabel"><label for="fullname">Full Name*</label><br /></span>
<input class="inputfield" type="text" id="fullname" name="fullname" size="30" value="<?php echo (isset($_POST['fullname'])) ? htmlentities($_POST['fullname']) : ""; ?>"/>
</div>
<div class="row">
<span class="formLabel"><label for="tel">Telephone*</label><br /></span>
<input class="inputfield" type="text" id="tel" name="tel" size="30" value="<?php echo (isset($_POST['tel'])) ? htmlentities($_POST['tel']) : ""; ?>"/>
</div>
<div class="row">
<span class="formLabel"><label for="email">Email Address</label><br /></span>
<input class="inputfield" type="text" id="email" name="email" size="30" value="<?php echo (isset($_POST['email'])) ? htmlentities($_POST['email']) : ""; ?>"/>
</div>
<div class="row">
<span class="formMessage">Message<br /></span>
<textarea class="inputarea" name="message" rows="5" cols="30"><?php echo (isset($_POST['message'])) ? htmlentities($_POST['message']) : ""; ?></textarea>
</div>
</fieldset>
<p><input type="submit" class="inputsend" name="SUBMIT" value="Send Form" /></p>
</form>
</body>
</html>
Bookmarks