NameSilo

Simple Contact Form

SpaceshipSpaceship
SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
Watch
I've wrote a simple contact form/script. Email validation etc. Hope you like it.

contact.php
PHP:
<?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 = "[email protected]";

//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:
1
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Nice and helpful, especially for beginners - great thing to learn from! Rep added!
 
0
Close
compuXP said:
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
 
0
Close
i might use that when i make an about us page, thats if i ever get around to doing so lol;)
 
0
Close
Thanks :)
*sigh* why did i bother to code my own, I should know SV is going to write one *sigh*
 
0
Close
Great work second :D
 
0
Close
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.
 
0
Close
DomainEasy: white label portfolios are live. Enable yours.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back