TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
Advertisement
Associates
Associates
techtuts Darkmindz
CSS Tutorials Tutorialsphere.com - Free Online Tutorials
Boston PHP SurfnLearn
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 09-26-2007, 08:35 PM   #1 (permalink)
The Visitor
 
Join Date: Sep 2007
Posts: 3
Thanks: 0
Mohamad is on a distinguished road
Smile Contact Us Form

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%">&nbsp;</td>
		<td colspan="2" class="style1">Contact Us</td>
		<td style="width: 25%">&nbsp;</td>
	</tr>
	<tr>
		<td style="width: 25%">&nbsp;</td>
		<td style="width: 25%">&nbsp;</td>
		<td style="width: 25%">&nbsp;</td>
		<td style="width: 25%">&nbsp;</td>
	</tr>
	<tr>
		<td style="width: 25%">&nbsp;</td>
		<td style="width: 25%">&nbsp;</td>
		<td style="width: 25%">&nbsp;</td>
		<td style="width: 25%">&nbsp;</td>
	</tr>
	<tr>
		<td style="width: 25%">&nbsp;</td>
		<td style="width: 25%">First Name:</td>
		<td style="width: 25%"><input name="firstname" type="text" size="30" />&nbsp;</td>
		<td style="width: 25%">&nbsp;</td>
	</tr>
	<tr>
		<td style="width: 25%">&nbsp;</td>
		<td style="width: 25%">Last Name:</td>
		<td style="width: 25%"><input name="lastname" type="text" size="30" /></td>
		<td style="width: 25%">&nbsp;</td>
	</tr>
	<tr>
		<td style="width: 25%">&nbsp;</td>
		<td style="width: 25%">E-Mail:</td>
		<td style="width: 25%"><input name="email" type="text" size="30" /></td>
		<td style="width: 25%">&nbsp;</td>
	</tr>
	<tr>
		<td style="width: 25%">&nbsp;</td>
		<td style="width: 25%">Mobile:</td>
		<td style="width: 25%"><input name="mobile" type="text" size="30" /></td>
		<td style="width: 25%">&nbsp;</td>
	</tr>
	<tr>
		<td style="width: 25%">&nbsp;</td>
		<td style="width: 25%">&nbsp;</td>
		<td style="width: 25%">&nbsp;</td>
		<td style="width: 25%">&nbsp;</td>
	</tr>
	<tr>
		<td style="width: 25%">&nbsp;</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>&nbsp;</td>
		<td style="width: 25%">&nbsp;</td>
	</tr>
	<tr>
		<td style="width: 25%">&nbsp;</td>
		<td style="width: 25%">&nbsp;</td>
		<td style="width: 25%">
		<input name="Submit1" type="submit" value="                  Send                  " dir="ltr" style="border:1px solid navy"/></td>
		<td style="width: 25%">&nbsp;</td>
	</tr>
	<tr>
		<td style="width: 25%">&nbsp;</td>
		<td style="width: 25%">&nbsp;</td>
		<td style="width: 25%">&nbsp;</td>
		<td style="width: 25%">&nbsp;</td>
	</tr>
	<tr>
		<td style="width: 25%">&nbsp;</td>
		<td style="width: 25%">&nbsp;</td>
		<td style="width: 25%">&nbsp;</td>
		<td style="width: 25%">&nbsp;</td>
	</tr>
	<tr>
		<td style="width: 25%">&nbsp;</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">&nbsp;</td>
	</tr>
	<tr>
		<td style="width: 25%" class="style1">&nbsp;</td>
		<td colspan="2" class="style1">Affordable webhosting and design 
		solutions</td>
		<td style="width: 25%" class="style1">&nbsp;</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
Attached Files
File Type: zip contactus.zip (1.6 KB, 25 views)
Mohamad is offline  
Reply With Quote
Old 09-26-2007, 10:21 PM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 1,587
Thanks: 72
Wildhoney is on a distinguished road
Default

Useful script, thank you for contributing. One thing I might add though is that HTML should be kept to a bare minimum for tutorials else you may end up just confusing individuals who are not well-learned when it comes to web languages. Nevertheless, good work!
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 09-27-2007, 10:59 AM   #3 (permalink)
The Visitor
 
Join Date: Sep 2007
Posts: 3
Thanks: 0
Mohamad is on a distinguished road
welcome

thanks wildhoney for replying

as you said, simple HTML codes :)


users can use this simpler one instead of the first one

HTML Code:
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Language" content="en-us" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled 1</title>
</head>

<body>

<form method="post" action="send.php">
	First name: <input name="firstname" type="text" /><br />
	Last name: <input name="lastname" type="text" /><br />
	email: <input name="email" type="text" /><br />
	mobile: <input name="mobile" type="text" /><br />
	message: <textarea name="message" cols="20" rows="2"></textarea><br />
	<input name="Submit1" type="submit" value="submit" /></form>

</body>

</html>
Mohamad is offline  
Reply With Quote
Old 10-03-2007, 12:25 PM   #4 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 1,587
Thanks: 72
Wildhoney is on a distinguished road
Default

Perfect, Mohamad. Thanks a lot for the contribution! Simple HTML is definitely the way forward so as you do not confuse people.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 10-03-2007, 03:22 PM   #5 (permalink)
The Visitor
 
Join Date: Sep 2007
Posts: 3
Thanks: 0
Mohamad is on a distinguished road
Default

any time ;)
Mohamad is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 10:48 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0