It will email the owner of a website, log the senders IP adress, verify if the sender filled all the fields and verify if the email adress is correct.
So lets begin.
Code:
<?php if(isset($_POST["send"]))
{
$name = $_POST["name"];
$url = $_POST["url"];
$email = $_POST["email"];
$subject = $_POST["subject"];
$msg = $_POST["msg"];
$ip = $_SERVER['REMOTE_ADDR'];
$receiver = "YOUREMAIL@DOMAIN.COM"; // CHANGE THIS
{
$name = $_POST["name"];
$url = $_POST["url"];
$email = $_POST["email"];
$subject = $_POST["subject"];
$msg = $_POST["msg"];
$ip = $_SERVER['REMOTE_ADDR'];
$receiver = "YOUREMAIL@DOMAIN.COM"; // CHANGE THIS
In this part, the script will gather some informations submited in the submition form, that will be under the whole code. This part of the script will check if the user as hit the Send Button, if yes, then the script will gather the information, if not it wont do a thing.
Code:
if(empty($name))
{
echo(" - There was no name!?);
}
function CheckMail($email) {
if (eregi(?^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*.[a-z]{2,4}$?, $email)) { return true; }
else { return false; }
}
if ((empty($email)) || (!CheckMail($email)))
{
Die(? - Please go back and fill in a valid e-mail adress!?);
}
if(empty($subject)){
echo(? - There was no subject!
?);
}
if(empty($msg)){
echo(? - There was no message!
?);
}
{
echo(" - There was no name!?);
}
function CheckMail($email) {
if (eregi(?^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*.[a-z]{2,4}$?, $email)) { return true; }
else { return false; }
}
if ((empty($email)) || (!CheckMail($email)))
{
Die(? - Please go back and fill in a valid e-mail adress!?);
}
if(empty($subject)){
echo(? - There was no subject!
?);
}
if(empty($msg)){
echo(? - There was no message!
?);
}
Now the script verifies if the fields are filled, and if the email adress is valid.
If everything is correct it will store the gathered informations in ONE variable.
Code:
// IF THEIR ARE NOT EMPTY
if(!empty($name) && !empty($email) && !empty($subject) && !empty($msg))
{
$headers .= "From: ".$email."";
// WE STORE THE MESSAGE IN A VARIABLE
$messageproper =
"This message was sent from: $name - $email n" .
"URLn" .
"------------------------- YOUR SITE Emailer -------------------------nn" .
"Name: $namen" .
"Site Url: $urln" .
"Email: $emailn" .
"Message: $msgn" .
"Sender Ip: $ipn" .
"n------------------------------------------------------------n";
mail("$receiver", $subject, $messageproper, "From: YOUR SITE Emailer < $email>?);
echo( ?
?????????????????????????????????????
Thank you ? . $name . ?, your email was sent! And your IP has been logged IP: ? .$ip .?
?????????????????????????????????????
? );} } ?>
if(!empty($name) && !empty($email) && !empty($subject) && !empty($msg))
{
$headers .= "From: ".$email."";
// WE STORE THE MESSAGE IN A VARIABLE
$messageproper =
"This message was sent from: $name - $email n" .
"URLn" .
"------------------------- YOUR SITE Emailer -------------------------nn" .
"Name: $namen" .
"Site Url: $urln" .
"Email: $emailn" .
"Message: $msgn" .
"Sender Ip: $ipn" .
"n------------------------------------------------------------n";
mail("$receiver", $subject, $messageproper, "From: YOUR SITE Emailer < $email>?);
echo( ?
?????????????????????????????????????
Thank you ? . $name . ?, your email was sent! And your IP has been logged IP: ? .$ip .?
?????????????????????????????????????
? );} } ?>
After the email is sent, in order to know if the email was sent, the scritp shows something like ?Thank you (the sender name here), your email was sent! And your IP has been logged?.
Actualy the sender doesn?t know that the IP will be logged so if he send you something you don?t like you can ban him from your website!

Now the form
Code:
<form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<strong>Name:</strong><br />
<input type="text" name="name" size="35" /><br />
<strong>Site Url:</strong>*<br />
<input type="text" name="url" size="35" /><br />
<strong>E-mail:</strong><br />
<input type="text" name="email" size="35" /><br />
<strong>Subject:</strong><br />
<input type="text" name="subject" size="35" /><br />
<strong>Message:</strong><br />
<textarea name="msg" rows="8" cols="42"></textarea><br />
<input type="submit" name="send" value="Send Email" /> <input type="reset" value="Reset" /><em>*Optional</em>
</form>
<strong>Name:</strong><br />
<input type="text" name="name" size="35" /><br />
<strong>Site Url:</strong>*<br />
<input type="text" name="url" size="35" /><br />
<strong>E-mail:</strong><br />
<input type="text" name="email" size="35" /><br />
<strong>Subject:</strong><br />
<input type="text" name="subject" size="35" /><br />
<strong>Message:</strong><br />
<textarea name="msg" rows="8" cols="42"></textarea><br />
<input type="submit" name="send" value="Send Email" /> <input type="reset" value="Reset" /><em>*Optional</em>
</form>
You can customize this code in order to make it look more like your site style, but be aware that I will not consider myself responsible for any act taken, if you damage the script, take it as your own risk.
So that should end with the script, now put all parts of the script in one file and name the file, contact.php, then link to it in your website. You can also upgrade the script, like making an IP banning, (if IP == 172.0.0.1 , dont send) lol

Note:note that in the code, there are some "YOUR WEBSITE" text, you will need to change this, and your email adress in the first part of the code.
You can download the working version of this script below.
If you can't download the file, please login or register.
Thanks.
Download : Complete Contact Form
Size: 0.001 mb - Hits : 1519
Size: 0.001 mb - Hits : 1519


