You will need 2 files. One will be a HTML page with a form on it. The other file will be pure php script that will phase the information from the HTML formant send it to you as an E-Mail.

Once the Form has been submitted a "Thanks we have your Message" message will appear to give the user feedback that the form has been accepted. The form will also clear itself ready for a new massage.


This is your form page. You can call it what ever you want. In this example I call this file index.php

Code:
<?php
session_start(); 
    // starts session that links the $_SESSION variable.. 

?>
<form action="mail_form.php" method="post">
<font face="Arial" size="3">
<?php
echo @$_SESSION['message'];  
    // this will insert "Thanks we have your Message" from mail_form.php

unset($_SESSION['message']);    
    // clears $_SESSION['message'] variable

?>
</font>
<table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr style="font-family: Arial;">
<input name="title" value="Web Developers > Web Languages > php > Mail to Form > " type="hidden">
<input type="hidden" name="returnto" value="<?php echo $_SERVER['PHP_SELF']; ?>">
</tr>
<tr>
<td style="width: 1034px;"><font face="Arial" size="2">Comments</font><br>
<textarea cols="60" rows="3" name="comments"></textarea><br>
<input value="Submit" type="submit"><input type="reset" value="Reset" name="Reset"></td>
</tr>
</tbody>
</table>
&nbsp;</form>
This is your php script. Saved as mail_form.php

Code:
<?session_start();   
   // starts session that links the $_SESSION variable..                
$comments=$_POST['comments'];  
   // gets the variable 'comment' from 

$to= your_return_email_address@woosh.co.nz; 
   // put your E-Mail address here. 
               $message="Comment:\n $comments"; 
    //   arranges data into $message ready to 
    //   be posted to you. 
    //   \n is a line return
               mail($to,"Comments From Your Site",$message); 
    //  mail () will E-Mail the data to you 
    //  $to:  is the E-Mail address to sent form data to
    //  "Comments From Your Site" Subject of E-Mail
    //  $message: The actual message you will receive.                     
               $_SESSION['message'] = "Thanks we have your Message";
    // Message sent back to index.php to let user know you have received
    // input...  
header("Location: " . $_POST['returnto']);
exit;
?>
And here is the example link:
Code:
http://udopage.com/examples/forms/simple.php