I found a php script on the old internet that i have decided to use for a site i'm doing.
I'm pretty rubbish with php etc, but I want to try and get this work.
Everything seems to be ok with it except:
1/ I would like validation on the e-mail. I have attempted this in the ereg part.
2/ WIll this protect from spam stuff?
Thanks,
Craig
<?php
// ------------- CONFIGURABLE SECTION ------------------------
// $mailto - set to the email address you want the form
// sent to, eg
//$mailto = "
youremailaddress@example.com" ;
$mailto = 'craigshaw1@yahoo.co.uk' ;
// $subject - set to the Subject line of the email, eg
//$subject = "Feedback Form" ;
$subject = "Feedback Form" ;
// the pages to be displayed, eg
$formurl = "
http://www.jgslimited.co.uk/contact_us.html" ;
$errorurl = "
http://www.jgslimited.co.uk/contact_error.html" ;
$thankyouurl = "
http://www.jgslimited.co.uk/contact_complete.html" ;
$uself = 0;
// -------------------- END OF CONFIGURABLE SECTION ---------------
$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$comments = $_POST['comments'] ;
$heardabout = $_POST['heardabout'];
$http_referrer = getenv( "HTTP_REFERER" );
if (!isset($_POST['email'])) {
header( "Location: $formurl" );
exit ;
}
if (empty($name) || empty($email) || empty($comments)) {
header( "Location: $errorurl" );
exit ;
}
if ( ereg('^[a-zA-Z0-9._-]+@[a-zA-Z0-9-] +\.[a-zA-Z.]{2,5}$', $email) ) {
header( "Location: $errorurl" );
exit ;
}
if (get_magic_quotes_gpc()) {
$comments = stripslashes( $comments );
}
$messageproper =
"This message was sent from:\n" .
"$http_referrer\n" .
"------------------------------------------------------------\n" .
"Name of sender: $name\n" .
"Email of sender: $email\n" .
"Heard about
: $heardabout\n" .
"------------------------- COMMENTS -------------------------\n\n" .
$comments .
"\n\n------------------------------------------------------------\n" ;
mail($mailto, $subject, $messageproper,
"From: \"$name\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.08" );
header( "Location: $thankyouurl" );
exit ;
?>