Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PHP Form code, a few questions.
Old 12-17-2007, 04:13 PM PHP Form code, a few questions.
Average Talker

Posts: 17
Name: Craig Shaw
Trades: 0
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 ;
?>
craigshaw is offline
Reply With Quote
View Public Profile Visit craigshaw's homepage!
 
 
Register now for full access!
Old 12-17-2007, 04:16 PM Re: PHP Form code, a few questions.
Experienced Talker

Posts: 30
Trades: 0
To validate an email address, you can use the next:

PHP Code:
if(!preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*?[a-z]+$/is'$email])){
 
header"Location: $errorurl);
 exit ;

klaroen is offline
Reply With Quote
View Public Profile
 
Old 12-18-2007, 08:16 AM Re: PHP Form code, a few questions.
Average Talker

Posts: 17
Name: Craig Shaw
Trades: 0
Thanks for the reply, I have changed that in my code and that seems to have done the trick.

I did have to change it slightly from what you put. After $email, there is a closing ] which I removed, otherwise it didn't work.

Also, as I said, I got this from the internet somewhere, will this protect the e-mail address from spam attacks?
craigshaw is offline
Reply With Quote
View Public Profile Visit craigshaw's homepage!
 
Old 12-18-2007, 11:21 AM Re: PHP Form code, a few questions.
Experienced Talker

Posts: 30
Trades: 0
Yes, my orgininal line was with the POST of email ($_POST['email']) sorry for that.

About the spam, currently there is no control if anybody makes a spam script for your form and sends you 1k of mails.... the best way is to put a vertification image in it.
If your're interested, I can give you a simple one.
klaroen is offline
Reply With Quote
View Public Profile
 
Old 12-19-2007, 04:33 AM Re: PHP Form code, a few questions.
Average Talker

Posts: 17
Name: Craig Shaw
Trades: 0
yes please, if you could send me a simple one, that would be great.

will i be able to easily integrate it into my existing form?
craigshaw is offline
Reply With Quote
View Public Profile Visit craigshaw's homepage!
 
Reply     « Reply to PHP Form code, a few questions.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 2.98704 seconds with 12 queries