Her

Home Web Programming PHP Form Email

Form Email

Author: Invano.com Author's URL: www.invano.com More by this author

This is a very simple tutorial, yet work like a charm and does all the things it needs to do. First of all, here's the code:

<?
$subject
= $_POST['subject']; // This is will be the subject of the email
$email = $_POST['email'];
$comments = $_POST['comments'];
$submit = $_POST['submit'];

if(
$submit)
{
// Replace [email protected] with your email address!
mail("[email protected]", "$subject", "$email", "$comments");

}
?>

Save it as contact.php

Lets break it down. The variables gather the information from the forms and make it a cleaner code. The if($submit) tells the mail(); function that it can send the email. It helps to keep it from sending annonymous emails to your email address.

You have to change the [email protected] to your email address to be able to get the email from the user. The rest is fine do not change, unless you need to.
Now for the forms!

<form method="post" action="contact.php">
Subject:<br />
<input type="text" name="subject" size="20"><br />
Email:<br /><input type="text" name="email" size="20"><br />
Comments:<br /><textarea cols="20" rows="5" name="comment"></textarea><br />
<input type="submit" value=" Submit "> </form>

which will produce the following

Subject:

Email:

Comments:

This is really simple, I should not have to explain it. Leave the name fields alone, unless you need to. You can change the size too.