AN EMAIL FORM

 

This tutorial will explain how to create a form that will submit the results to your email. The most popular way of doing this is through CGI scripts which are often complicated and involve a lot of configuration before you can easily use them. This is a simple script that will take the submitted contents, generate an email and send them out.

To begin I have created a new directory on my site and called in contact. now we can create a new PHP file called contact.php. Insert the following code into it:
<form method="post" action="send.php">
<INPUT TYPE="TEXT" value="[email protected]" NAME="email" size=20> <br>
<INPUT TYPE="TEXT" value="Subject" NAME="subject" size=20> <br>
<TEXTAREA NAME="comments" value="Your Message Here" ROWS=5 COLS=20>Your Message Here</TEXTAREA> <br>
<input type="submit" name="submit" value="Email Me!"> <input type="reset" name="reset" value="Reset"> <br>
</form>

You can of course change the fields and add new ones, i used a simple one because it makes it easier to explain. Now we need to make another file called send.php. This is where the form will submit the data and this is the actual script which will generate and send the email. Insert the following code into send.php:
<?php
mail("[email protected]", "$subject", "$email", "$comments");
echo("Thanks $email!<BR>\nBelow shows what was sent<BR><BR>\nSubject: $subject<BR>
Email: $email
\nMessage: $comments");
?>

Now its time for the customizing. Change [email protected] to the email address you wish for this form to be sent to. The next link $subject", "$email", "$comments lists the names of the fields you have used. If you add any new fields or rename the current ones make sure to edit that line.

Now save both files and upload them to your server. You can choose to place them into a separate directory as I did but that is not required.

 

Hosted by www.Geocities.ws

1