Good afternoon everyone,
Here I will show you how to create a contact us form
this script contains two pages
index.htm
send.php
the user will fill in the form from the html page where the data will be sended to the php file using the function POST.
index.htm
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
<meta http-equiv="Content-Language" content="en-us" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact Us Form || By Des4Hosting.com</title>
<style type="text/css">
.style1 {
text-align: center;
}
.style2 {
font-family:Verdana;
font-size:x-small;
color:navy;
text-decoration:none;
background-color:#CEE7FF;
}
.style3 {
text-decoration: none;
}
</style>
</head>
<body class="style2">
<form action="send.php" method="post">
<table align="center" style="width: 600px">
<tr>
<td style="width: 25%"> </td>
<td colspan="2" class="style1">Contact Us</td>
<td style="width: 25%"> </td>
</tr>
<tr>
<td style="width: 25%"> </td>
<td style="width: 25%"> </td>
<td style="width: 25%"> </td>
<td style="width: 25%"> </td>
</tr>
<tr>
<td style="width: 25%"> </td>
<td style="width: 25%"> </td>
<td style="width: 25%"> </td>
<td style="width: 25%"> </td>
</tr>
<tr>
<td style="width: 25%"> </td>
<td style="width: 25%">First Name:</td>
<td style="width: 25%"><input name="firstname" type="text" size="30" /> </td>
<td style="width: 25%"> </td>
</tr>
<tr>
<td style="width: 25%"> </td>
<td style="width: 25%">Last Name:</td>
<td style="width: 25%"><input name="lastname" type="text" size="30" /></td>
<td style="width: 25%"> </td>
</tr>
<tr>
<td style="width: 25%"> </td>
<td style="width: 25%">E-Mail:</td>
<td style="width: 25%"><input name="email" type="text" size="30" /></td>
<td style="width: 25%"> </td>
</tr>
<tr>
<td style="width: 25%"> </td>
<td style="width: 25%">Mobile:</td>
<td style="width: 25%"><input name="mobile" type="text" size="30" /></td>
<td style="width: 25%"> </td>
</tr>
<tr>
<td style="width: 25%"> </td>
<td style="width: 25%"> </td>
<td style="width: 25%"> </td>
<td style="width: 25%"> </td>
</tr>
<tr>
<td style="width: 25%"> </td>
<td style="width: 25%">Message:</td>
<td style="width: 25%">
<textarea name="message" cols="30" dir="ltr" style="height: 89px">Type your message here...</textarea> </td>
<td style="width: 25%"> </td>
</tr>
<tr>
<td style="width: 25%"> </td>
<td style="width: 25%"> </td>
<td style="width: 25%">
<input name="Submit1" type="submit" value=" Send " dir="ltr" style="border:1px solid navy"/></td>
<td style="width: 25%"> </td>
</tr>
<tr>
<td style="width: 25%"> </td>
<td style="width: 25%"> </td>
<td style="width: 25%"> </td>
<td style="width: 25%"> </td>
</tr>
<tr>
<td style="width: 25%"> </td>
<td style="width: 25%"> </td>
<td style="width: 25%"> </td>
<td style="width: 25%"> </td>
</tr>
<tr>
<td style="width: 25%"> </td>
<td colspan="2" class="style1">Written by
<a href="http://www.des4hosting.com/" class="style3">Des4Hosting.com</a></td>
<td style="width: 25%" class="style1"> </td>
</tr>
<tr>
<td style="width: 25%" class="style1"> </td>
<td colspan="2" class="style1">Affordable webhosting and design
solutions</td>
<td style="width: 25%" class="style1"> </td>
</tr>
</table>
</form>
</body>
</html>
send.php
PHP Code:
/** Contact us form
* written by Des4Hosting.Com Programming team
* September 2007
* Suggestions and explanations are welcome
* support@des4hosting.com
* Please do not remove the copyrights without permission
**/
<?
$to = "support@des4hosting.com"; //write in the email of the receipient
$subject = ""; // the subject of the message
//do not edit below this line unless you are sure what you are doing
$fn= $_POST['firstname'];
$ln= $_POST['lastname'];
$email= $_POST['email'];
$mobile= $_POST['mobile'];
$message= $_POST['message'];
$mail_headers .= "From: ". $fn ."<" . $email . ">" . "\r\n";
$body= "
A visitor of your site wrote:
My name is: $fn $ln
My Email is: $email
You can call me on: $mobile
Message:
$message
Thank you for replying on my enquiry";
if(mail($to,$subject,$body,$mail_headers)) {
echo " your message has been sent successfuly";
} else {
echo "there was an error sending your request, please try again later!";
}
?>
let me explain the procedure so you can modify the file to meet your needs
we have 5 varables that will hold the data,
fn for the firstname
ln for the lastname
email for email
mobile for mobile
message for message
regarding this line :
$mail_headers .= "From: ". $fn ."<" . $email . ">" . "\r\n";
this line can be modified as follows
$fn, as prementioned for the first name
so the receipient will see the firstname of the sender in the section From in his mail client
$email , again as prementioned for sender's email
so the receipient will see that he received an email from the email of the sender
I guess that's all, everything else is clear
any questions are welcome thru the forum or
support@des4hosting.com
you will find the script attached