...

View Full Version : Easy Contact Form.



JasonReynolds
01-20-2010, 03:38 PM
Hey guys, i read endless times that people are going wrong with email forms... so i have a solution, Here is an easy quick tutorial on how to create a simple email form directing to the email address you wish.

First create a " contact.php "

<style type="text/css">
.style1 {
text-align: center;
}
</style>
<div class="style1">
<strong><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

</strong>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<strong>
<title>Email Form </title>
</strong>
</head>
<body style="background-color: #0000FF">

</div>

<form method="post" action="sendemail.php">

<div class="style1">
<strong>

<!-- DO NOT change ANY of the php sections -->
<?php
$ipi = getenv("REMOTE_ADDR");
$httprefi = getenv ("HTTP_REFERER");
$httpagenti = getenv ("HTTP_USER_AGENT");
?></strong> <strong>

<input type="hidden" name="ip" value="<?php echo $ipi ?>" />
<input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
<input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />


Your Name: <br />
<input type="text" name="visitor" size="35" /></strong> <strong>
<br />
Your Email:<br />
<input type="text" name="visitormail" size="35" /></strong> <strong>
<br /> <br />
<br />
Attention:<br />
<select name="attn" size="1">
<option value=" Sales and Billing ">Sales and Billing </option>
<option value=" General Support ">General Support </option>
<option value=" Technical Support ">Technical Support </option>
<option value=" Registration Issues ">Registration Issues </option>
</select></strong> <strong>
<br /><br />
Message:
<br />
<textarea name="notes" rows="4" cols="40"></textarea></strong> <strong>
<br />
<input type="submit" value="Send Mail" /></strong> <strong>
<br />
</strong></div>
</form>

</body>
</html>

Okay so the line where it says "<option value=" Sales and Billing ">Sales and Billing </option> " you can change the "Sales and Billing" to anything you want, the first "Sales and Billing" will appear if they select that into your inbox, the second one will be what the customers see. So pretty easy so far?

Next create a " sendemail.php "

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Reply</title>
<style type="text/css">
.style1 {
color: #FF0000;
}
</style>
</head>
<body style="background-color: #0000FF">

<!-- Reminder: Add the link for the 'next page' (at the bottom) -->
<!-- Reminder: Change 'YourEmail' to Your real email -->

<?php

$ip = $_POST['ip'];
$httpref = $_POST['httpref'];
$httpagent = $_POST['httpagent'];
$visitor = $_POST['visitor'];
$visitormail = $_POST['visitormail'];
$notes = $_POST['notes'];
$attn = $_POST['attn'];


if (eregi('http:', $notes)) {
die ("Do NOT try that! ! ");
}
if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
echo "<h2>Oops! you did not fill in all the information please go back - Enter information</h2>\n";
$badinput = "<h2>Feedback was NOT submitted you shall now be re-directed back to the contact form.</h2>\n";
echo $badinput;
die ("Hmm Error ");
}

if(empty($visitor) || empty($visitormail) || empty($notes )) {
echo "<h2><center>Oops! you did not fill in all the information please go back - Enter valid information</center></h2>\n";
die ("<center>Feedback was NOT submitted you shall now be re-directed back to the contact form.</center> ");
}

$todayis = date("l, F j, Y, g:i a") ;

$attn = $attn ;
$subject = $attn;

$notes = stripcslashes($notes);

$message = " $todayis [EST] \n
Attention: $attn \n
Message: $notes \n
From: $visitor ($visitormail)\n
Additional Info : IP = $ip \n
Browser Info: $httpagent \n
Referral : $httpref \n
";

$from = "From: ivii contact form";


mail("!!!Your Email Here!!!", $subject, $message, $from);

?>

<p align="center">
Date: <?php echo $todayis ?>
<br />
Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> )
<br />

Attention: <?php echo $attn ?>
<br />
Message:<br />
<?php $notesout = str_replace("\r", "<br/>", $notes);
echo $notesout; ?>
<br />
<?php echo $ip ?>

<br /><br />
<p align="center" class="style1">
<strong>You shall now be re-directed to our home page.</strong></p>
<META HTTP-EQUIV="Refresh"
CONTENT="3; URL=!!!Your Home Page!!!">
</body>
</html>

Basicly you should change the sections where it says "!!!Your email here!!!" and also "!!!Your Home Page!!!" This shall you can change the number near the bottom of the code where it says "CONTENT="3;" how many ever seconds you want the person to wait until they are re-directed to a URL you wish.

This was an easy simple tutorial, Thankyou for reading Hope it helped. :D:D

masterofollies
01-20-2010, 03:41 PM
This needs to go in the PHP Snippet area.

tomws
01-20-2010, 03:45 PM
It also puts a style outside of the html tags and sticks the doctype in a div?

JasonReynolds
01-20-2010, 03:47 PM
It also puts a style outside of the html tags and sticks the doctype in a div?

Sorry, i forgot to enter "<" let me add it to the code, That should work now

_Aerospace_Eng_
01-20-2010, 07:05 PM
What is the point of this?

<META HTTP-EQUIV="Refresh"
CONTENT="3; URL=!!!Your Home Page!!!">
It can't go within the body like you have it and php does have refresh headers that allow you to use seconds to determine when to refresh.

prasanthmj
01-21-2010, 02:35 AM
The From field of the email should be a proper email value. Some email servers will reject if it is not.


$from = "From: ContactForm<Your email here>";

See: Why is my PHP script not sending emails? (http://www.html-form-guide.com/blog/php-form-email/3/php-script-not-sending-email/) for details.

JasonReynolds
01-31-2010, 11:38 AM
But even so it works. And i preffer META



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum