HTML Code for a Contact Form?

Ferret Lady

Well-known member
hey guys. i'm working on a new website for my company and i'm trying to add a little contact form on it but really having difficulty. i've gone through about 30 of the results google gave me but each one has one problem or another. I just want a simple easy to use html code i can copy and paste on my site for people to enter their name, email, and a message.

something i can easily just fill in my email address somewhere and they click submit and it comes to me. argg... but i dont really understand this php stuff, seems i have to create a php page as well as the contact.html page.

anytime i find a good form it redirects the person to the website that created the code which i dont want... i want the user to go to another page on my website once they press submit..

can somebody help me ??? i'm gonna bang my head on this desk till you do..

much thanks :) heh.
 
You have to edit the variables in the PHP code. Most of them point to the authoring website by default. It is not too difficult. A lot of forms only have one or two lines of code to edit. Then you have to target your form (html side) to post to the php or perl script that runs server side. It will then parse the results back to you in an email.
 
did you make this for me? i noticed that when i viewed the php file it took me to one of the pages of my own website...

do i copy the source html of that link and thats it? or is there a second php page i have to creat?

This is the markup of the html page mailtest.html :

<html>
<head>
<title>Mailtest</title>
<head>
<body>
<form method="post" action="http://snurdo.com/mailtest.php">
Your Name: <input name="name" type="text" /><br />
Your Email Address: <input name="address" type="text" /><br />
<input type="submit" name="submit" value="Send Form Info" />
</form>
</body>
</html>

Here is the entire code of the php page which is saved as mailtest.php :

<?php
mail("info@getfamousproductions.com","Form_Testing","Name: " . $_REQUEST['name'] . "\nEmail Address: " . $_REQUEST['address'],"From:form_handler@getfamousproductions.com");
header("Location: http://getfamousproductions.com/videos.html" );
?>

The first line is the mail function. The second line is the header function.

So that's it. Two php functions on the php page plus the form from the original html page. Inside the mail function the two variables 'name' and 'address' are referenced through the php array variables $_REQUEST['name'] and $_REQUEST['address']

These are concatenated onto two strings. The \n forces new lines in the body of the email message. The header function is what redirects you to your video page after the email message is sent.

On the html page the action value is what directs you to this php page. Put these on your site and change the action value to point to the php page on your site to local relative reference instead of the absolute reference it is now.
 
Last edited:
You'll have to use both some complicated HTML as well as some PHP. It's rather difficult to get right on your own if you want to protect the privacy of the individuals giving you their information.

Since it's not that big a deal in your case, I'd just go onto www.mturk.com and maybe check out some freelancing forums for web designers, and you might be able to get somebody to do it for you for about $20 or so.
 
This is the markup of the html page mailtest.html :

<html>
<head>
<title>Mailtest</title>
<head>
<body>
<form method="post" action="http://snurdo.com/mailtest.php">
Your Name: <input name="name" type="text" /><br />
Your Email Address: <input name="address" type="text" /><br />
<input type="submit" name="submit" value="Send Form Info" />
</form>
</body>
</html>

Here is the entire code of the php page which is saved as mailtest.php :

<?php
mail("info@getfamousproductions.com","Form_Testing","Name: " . $_REQUEST['name'] . "\nEmail Address: " . $_REQUEST['address'],"From:form_handler@getfamousproductions.com");
header("Location: http://getfamousproductions.com/videos.html" );
?>

The first line is the mail function. The second line is the header function.

So that's it. Two php functions on the php page plus the form from the original html page. Inside the mail function the two variables 'name' and 'address' are referenced through the php array variables $_REQUEST['name'] and $_REQUEST['address']

These are concatenated onto two strings. The \n forces new lines in the body of the email message. The header function is what redirects you to your video page after the email message is sent.

On the html page the action value is what directs you to this php page. Put these on your site and change the action value to point to the php page on your site to local relative reference instead of the absolute reference it is now.


this is awesome craig. totally what i was looking for, and easy to implement.

i just have two questions on how to customize it.

1) how can make it so the two boxes will be lined up perfectly so they're directly on top of each other? and,

2) how can i add a third box, which is larger, that they can put in a comment/question?

thanks again!!!! i'm excited to get this functioning on my site!
 
Change the html to inlcude a table in the form and a textarea tag like this:

<form action="mailtest.php" method="post">
<table width="800" border="0">
<tr><td align="right">Name: </td><td><input type="text" name="name" size="50" /></td></tr><tr><td align="right">Email Address: </td><td><input type="text" size="50" /></td></tr><tr>
<td align="right">Comments: </td><td><textarea rows="9" cols="42">
</textarea></td></tr><tr><td colspan="2"><input type="submit" value="Send Form" name="submit" /></td></tr>
</table>
</form>

Setting border to 0 as table attribute hides the border.
 
For lining up the form boxes you could remove the size and cols attributes and instead throw in a little page level css like this:

<html>
<head>
<title>Mailtest</title>
<style type="text/css">
.bob {
width:300px;
}
</style>
<head>
<body>
<form method="post" action="http://snurdo.com/mailtest.php">
Your Name: <input name="name" type="text" /><br />
Your Email Address: <input name="address" type="text" /><br />
<input type="submit" name="submit" value="Send Form Info" />
</form>
<form action="mailtest.php" method="post">
<table width="800" border="0">
<tr><td align="right">Name: </td><td><input type="text" name="name" class="bob" /></td></tr><tr><td align="right">Email Address: </td><td><input type="text" class="bob" /></td></tr><tr>
<td align="right">Comments: </td><td><textarea rows="9" class="bob">
</textarea></td></tr><tr><td colspan="2"><input type="submit" value="Send Form" name="submit" /></td></tr>
</table>
</form>

</body>
</html>
 
awesome.

hate to be a pain, cuz i really appreciate you helping me with this craig, but now the php form doesnt seem to work properly. when i use the form, the email i end up getting has the name and the filled in text, but he email field is empty, and i get no comment/question at all.

i put a test one here, maybe you can tell me how to change the php file to fix it , i tried to add it in my self using logic but i failed.. hahahha...

http://www.getfamousproductions.com/testcontact.html

the php file for this is what you gave me at first, slightly edited:

<?php
mail("info@getfamousproductions.com","Form_Testing ","Name: " . $_REQUEST['name'] . "\nEmail Address: " . $_REQUEST['address'],"From:form_handler@getfamousproductions.com");
header("Location: http://getfamousproductions.com/index.html" );
?>
 
Try this for html page, (Notice the name="address" for input field for email address and name="comments" in textarea field. Those are what label each tag for the php array):

<html>
<head>
<title>Mailtest</title>
<style type="text/css">
.bob {
width:300px;
}
</style>
<head>
<body>
<form action="mailtest.php" method="post">
<table width="800" border="0">
<tr><td align="right">Name: </td><td><input type="text" name="name" class="bob" /></td></tr><tr><td align="right">Email Address: </td><td><input name="address" type="text" class="bob" /></td></tr><tr>
<td align="right">Comments: </td><td><textarea rows="9" class="bob" name="comments">
</textarea></td></tr><tr><td colspan="2"><input type="submit" value="Send Form" name="submit" /></td></tr>
</table>
</form>

</body>
</html>

And this for the updated php:


<?php
mail("info@getfamousproductions.com","Form_Testing","Name: " . $_REQUEST['name'] . "\nEmail Address: " .$_REQUEST['address'] . "\nComments: " . $_REQUEST['comments'],"From:form_handler@getfamousproductions.com");
header("Location: http://getfamousproductions.com" );
?>
 
Back
Top