Results from the most recent live auction are here .
21 members in the live chat room. Join Chat !
09-30-2005, 08:15 PM
· #1 while ($awake){ code(); }
Name: Eric
Location: Kentucky
Join Date: Mar 2005
Posts: 4,195
NP$: 1660.00 (
Donate )
Simple Contact Form
I've wrote a simple contact form/script. Email validation etc. Hope you like it.
contact.php
PHP Code:
<?php
/*
SVs SimpContact v1.0.0
Copyright © 2005 SecondVersion
http://www.secondversion.com
*/
echo 'You can use the following form to contact us.
<br>
All fields required.
<br>
<form method="post" action="contact.php">
Name:
<br>
<input type="text" name="name" size="20">
<br>
<br>
E-mail address:
<br>
<input type ="text" name="email" size="20">
<br>
<br>
Subject:
<br>
<input type ="text" name="sub" size="20">
<br>
<br>
Message:
<br>
<textarea rows="5" cols="35" name="message" wrap="virtual"></textarea>
<br>
<input type="submit" name="submit" value="Submit">
<br>
<br>
Powered by: <a target="_blank" href="http://www.secondversion.com">SVs SimpContact v1.0.0</a>.
</form>' ;
if(!empty( $_POST [ 'submit' ]))
{
$name = $_POST [ 'name' ];
$message = $_POST [ 'message' ];
$email = $_POST [ 'email' ];
$sub = $_POST [ 'sub' ];
$ip = $_SERVER [ 'REMOTE_ADDR' ];
//Check for a valid email..
$validate = eregi ( "^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$" , $email );
if(! $validate )
{
echo( "<br>" . $email . " is not a valid email." );
}
else
{
$e = $email ;
}
//Required Fields, you can add or remove fields as neccessary.
//Did they leave them empty?
if(! $name || ! $message || ! $e )
{
echo '<br>One or more required fields were left blank, please enter all required data.' ;
}
else
{
//Get the date...
$date = date ( "M d Y" );
//What email do you want it sent to?
$youremail = "you@domain.com" ;
//What subject to do want the email to be?
$subject = "Subject" ;
//Send the data...
$name = stripslashes ( $name );
$subj = stripslashes ( $sub );
$message = stripslashes ( $message );
$msg = wordwrap ( $message , 70 , "<br>" );
$headers = 'From: ' . $e . '' ;
$send = mail ( "$youremail" , "$subject" , "
<b>Name:</b> $name
<b>E-mail address:</b> $e
<b>Subject:</b> $subj
<b>Message:</b>
$msg
<b>Message sent on:</b> $date
<b>IP:</b> $ip
" , $headers );
if( $send )
{
echo '<br>Thanks for contacting us.' ;
}
else
{
echo '<br>Seems to be a problem, please try again later.' ;
}
}
}
?>
</body>
</html>
Enjoy!
-Eric
Last edited by SecondVersion : 10-06-2005 at 10:33 PM .
09-30-2005, 08:20 PM
· #2 DNOA Member
Name: Matthew Holt
Location: 127.0.0.1
Join Date: May 2004
Posts: 4,867
NP$: 17.21 (
Donate )
Nice and helpful, especially for beginners - great thing to learn from! Rep added!
__________________
FREE : Help With Code
Includes other technical topics:
programming, development, Windows, domain names, and Internet
09-30-2005, 08:48 PM
· #3 while ($awake){ code(); }
Name: Eric
Location: Kentucky
Join Date: Mar 2005
Posts: 4,195
NP$: 1660.00 (
Donate )
Originally Posted by compuXP Nice and helpful, especially for beginners - great thing to learn from! Rep added!
Thanks.
Yeah, I kept that in mind when writing it, wanted to keep it as simple as possible. And posted it in the hopes a beginner etc would take it learn/build on it. Hope it helps a few.
-Eric
09-30-2005, 08:55 PM
· #4 Senior Member
Name: Jordan Lutz
Location: Regina, Sask, Canada
Join Date: May 2005
Posts: 1,323
NP$: 12.15 (
Donate )
i might use that when i make an about us page, thats if i ever get around to doing so lol
09-30-2005, 10:10 PM
· #5 Senior Member
Name: Joshua Henderson
Location: Australia
Join Date: Apr 2005
Posts: 1,101
NP$: 1.30 (
Donate )
Thanks
*sigh* why did i bother to code my own, I should know SV is going to write one *sigh*
10-04-2005, 10:22 AM
· #6 Senior Member
Name: Zubair
Location: Ontario Canada
Join Date: May 2005
Posts: 2,746
NP$: 718.15 (
Donate )
Great work second
10-04-2005, 11:05 AM
· #7 Senior Member
Join Date: Mar 2004
Posts: 1,404
NP$: 2705.50 (
Donate )
Your email validation regex has some problems. There are a number of valid mailbox characters you haven't included. In particular the “+” which I've seen quite a few times.
I appreciate that you allow for a host name instead of limiting users to a mailbox and domain name like many broken scripts. However, while technically possible, I doubt you need to allow for hosts with an underscore, and certainly not a percent.
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off