PHP Tutorials

XMLStyleSoldierFlowerMonkey

Form Mail

Learn how to make a Form Mail using the power of PHP.

Spreadshirt
One of the most important scripts which is used online is the Mail Form. Fortunately, PHP makes it extremly easy to use form mail, using the mail() function. So the Form Mail we're going to make is going to be broken does into 2 parts. One part has the HTML for the form and the second part is the processing for the form. However, we have to work backwards and do the processing before hand. We will ask three things on the form to keep it simple: their name, their e-mail address, and their comments. Lets get started with the first part:

Here is what we have to write in English for the processing:
  1. If Submit gets hit
  2. Run the e-mail and send it
Here it is in PHP:
<? //initilize PHP
if($submit) //If submit is hit
{
    mail("youremailaddress@whatever.com", "$subject", "$email", "$comments");
}?>
And here is the form for the sending this file. Its fairly simple and easy to understand if you know HTML. Now here is the processing in English:
  1. If submit is not hit, then display the form.
  2. Have the send button.
Here it is in PHP:
<? else
{?>

    <form method="post" action="comments.php">
    //comments.php = the name of this script
    E-Mail: <INPUT TYPE="TEXT" NAME="email" size=60> //their email address
    Subject: <INPUT TYPE="TEXT" NAME="subject" size=60> //subject
    Comments: <TEXTAREA NAME="comments" ROWS=10 COLS=30></TEXTAREA> //comments
    <input type="submit" name="submit" value="submit">
    </form>

<? }?>
Not too tough was it? Well thats it folks. If you want to add more sections to the comments section, just use the PHP .= function to keep adding string together. I hope it works out for you and if it doesn't, email for help at webmaster@spoono.com and we'll try to help you out.

Discuss this tutorial »
Written by: Akash Goel
Back to PHP TutorialsTop


Copyright © 2000-2010 Spoono, LLC. All rights reserved.
Network: Reseller Web Hosting by Spoono Host | Spoonloads | Absolute Cross
Terms of Service | Privacy Policy.

kdfj