Log in

View Full Version : How DO I Make a Contact Form?! I Give Up!



MrRSMan
08-21-2007, 10:09 PM
I need to create a very simple contact form for my site. Let's just say it's a single field where you put your name, and then you click "submit" and it emails it to me.

I have tried a simple HTML mail form, but all it does is open Outlook Express and present me with a large pop-up box saying that my account is set up (I don't use Outlook). Anyway, I don't want this to happen at all whether the person uses Outlook or not. This code, I will add, was from a "email form maker" where all it does is present you with the raw code.

I then went on to using a PHP form. This too was also taken from an "email form maker", where it just gives you the code. This worked, up to the point that you clicked the "Submit" button, where is transferred me the contact.php, which displayed only the raw code used on that page!

Please help me! I give up! Could you please give the EXACT code for the page(s), so all I have to do is save it- everything I try to do just goes wrong!

As far as I know, to make an email form in PHP, there should be two pages- contact.htm and contact.php, but I may be incorrect.

Thank you for your help! I need it!

MrRSMan.

djr33
08-22-2007, 12:18 AM
There are five ways to make a contact form:

1. use action="mailto:....", as you did originally. Not very professional, but requires no coding.

2. Use a free form mailer. This submits the form to an external site already configured for sending out the email. If you don't want to code and don't mind preformatted emails, usually with ads, then that is an option. Google "free form mailer" and look at the results. Directions are fairly basic. Just point the form action="http://that.com/their.form", and then add a bit of code as described on their page.

3. Use a premade server side script. (See below)

4. Write your own server side script. This is a good idea if you want control and a smooth system, but a bit more work.
You will write a script in PHP (or ASP, CGI, etc.) to take the data from the form and do stuff with it, including sending an email.

5. Use an applet or plugin based thing, such as flash or java. I wouldn't recommend these as it can be accomplished without and they are a pain to deal with and some users don't have them installed.

Some hosts also have default contact form setups, so you might want to look at your cpanel, etc.

Note that with each method, the HTML form will be nearly identical, with the exception of the action. (Some free form mailers or PHP scripts might need special fields to know things, like the "email" field might be where the message is sent.)



It sounds like what you were doing would work and I would recommend pursuing it. The problem with the code being displayed sounds like PHP was not working.
Generally, you need three things to make PHP code work on a page:
1. Surround it in <?php ..... ?> tags.
2. The page must end in the .php extension (or your server can be configured for other extensions, but you would know if this is the case).
3. You must have the PHP parser setup and enabled on your server.

Based on what you said, I'm guessing it's (3). Your host may not support PHP, or you may need to install or request it.

To check you could use:
<?php echo "test"; ?> (should output "test")
Or, <?php phpinfo(); ?> which would display server configuration for PHP, if installed.

If you determine that PHP cannot be used you could consider another server side language, if available, such as ASP or CGI, or you will have to choose one of the other options. I'd recommend a free form mailer.


If you do need more information or example scripts, please do a search on the forum as there have been many, many discussions of this issue and a number of scripts have been written.


Good luck.

kidambi502002
08-31-2007, 01:15 PM
try to build a ready made form with a few clicks thru coffeecup flash form builder with a lot of embellishments. this gives codes to be inserted at appropriate place in the web page as well a few files to be uploaded to the root folder of your site.

boogyman
08-31-2007, 01:33 PM
if you do the test that djr said to and it works you can use this code as your contact.php

contact.php


<?php

//EDIT THESE 2 FIELDS WITH YOUR INFO
$to = "_YOUR_EMAIL_ADDRESS_";
$subject = "_SUBJECT_OF_EMAIL_";


// NO NEED TO EDIT PAST HERE
$message = "";
foreach($_REQUEST as $k => $v) {
$message .= trim(strip_tags($k)) . ": " . trim(strip_tags($v)) . "<br>";
}

if( !mail($to, $subject, $message) )
{
echo "<p>Could Not Send Email.. Please Try Again Later</p>";
}
else
{
echo "<p>Email Sent. Thank You!</p>";
}
?>



that will take whatever is submitted and create an email out of it.
as for creating the html form part, well that is all dependent on what you wish to put in the email but a simple form is below

contact.html


<!DOCTYPE HTML PUBLIC "-//W3C/DTD HTML 4.01//EN "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>TITLE OF PAGE</title>
</head>
<body>

<form name="form" action="contact.php" method="post">
<p>
<label>Name:</label>
<input type="text/css" name="name" value="">
</p>
<p>
<label>Email:</label>
<input type="text/css" name="email" value="">
</p>
<input type="submit" name="submit" value="Send Email">
</form>

</body>
</html>

eleven82
08-31-2007, 08:08 PM
Follow this tutorial, you'll be fine with it. I use it on my site and it works everytime.

http://www.trap17.com/index.php/php-contact-form_t4780.html

Twey
08-31-2007, 08:21 PM
I then went on to using a PHP form. This too was also taken from an "email form maker", where it just gives you the code. This worked, up to the point that you clicked the "Submit" button, where is transferred me the contact.php, which displayed only the raw code used on that page!This sounds like your server does not support PHP.
try to build a ready made form with a few clicks thru coffeecup flash form builderIt will still rely on a server-side script of some sort, plus relying on plugin content for a function like this is an accessibility nightmare.

prince0
09-03-2007, 05:55 PM
The web form

First of all, you need to construct your web form. This should start with the following...
<form method="POST" action="thanks.php">
The 'method' parameter indicates that all variables (data) collected are to be hidden and not placed in the URL. The most important part is the 'action' parameter as this indicates where the processing of the form should be done. The form may also be given a name but as this is optional, we've left it out in this case to keep everything simple.
Our example form will collect a name and an email address. The following lines will do this.

Name: <input type="TEXT" name="name">
Email: <input type="TEXT" name="email">
Then we need a submit button and a tag to indicate the end of the form.
<input type="SUBMIT" name="Submit" value="ok">
</form>

The thanks page
Once someone has clicked on the ok button to submit the details on our form, we should let them know that their form has been submitted. For this we need a thanks page. This should be a normal html page which you will have constructed. You should then rename your thanks page to 'thanks.php'. The php extension enables the web server to run the php code on that page before it is sent to the browser.
Under the <BODY> tag on your thanks page, please enter the following code...
<script language="php">
$email = $HTTP_POST_VARS[email];
$mailto = "email@address";
$mailsubj = "Form submission";
$mailhead = "From: $email\n";
reset ($HTTP_POST_VARS);
$mailbody = "Values submitted from web site form:\n";
while (list ($key, $val) = each ($HTTP_POST_VARS)) { $mailbody .= "$key : $val\n"; }
if (!eregi("\n",$HTTP_POST_VARS[email])) { mail($mailto, $mailsubj, $mailbody, $mailhead); }

Make sure that you replace 'email@address' in the code with your own email address.

It is better you use your own webmail instead of yahoo as it may not deliver to yahoo but your own webmail is a sure delivery

boogyman
09-03-2007, 06:14 PM
Make sure that you replace 'email@address' in the code with your own email address.


ps.. just to let you know... dark red is probably not the best color to chose ... eg.. color blind. I am colorblind but I was able to pick up on the very slight change with alot of concentration :/ and a headache in the end. It would be alot better if you chose something much more drastic of a color change... like blue or pink ...
pss.. Green and Red are usually the colors people who are color blind have a problem distinguishing :)

prince0
09-04-2007, 07:01 AM
The words in red is just an instruction and not part of the code, anyway, have see it in blue as you have requested.

Make sure that you replace 'email@address' in the code with your own email address.

tech_support
09-04-2007, 07:10 AM
Why <script language="php"> instead of <?php ... ?> ?

And, FYI, you forgot to close the <script> tag :)

shriniwas
12-27-2007, 11:49 AM
I used the php source but it resulted in this :
:confused:
Could Not Send Email.. Please Try Again Later

Can some one help me out in this ??..:o

TimFA
12-28-2007, 11:23 PM
If your using a free host often they have mail() disabled, so that is most likely the problem. Also I'm not color blind and couldn't see that red very well at all. Light red yes, but dark red? I'm not like trying to be mean or something, I just don't understand why you used it...

kit
10-11-2008, 03:39 PM
Follow this tutorial, you'll be fine with it. I use it on my site and it works everytime.

http://www.trap17.com/index.php/php-contact-form_t4780.html

I tried that tutorial, everything works, besides when i get emails, no info shows up, except the subject.