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.
Form Mail
Learn how to make a Form Mail using the power of PHP.
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:
- If Submit gets hit
- 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:
- If submit is not hit, then display the form.
- 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.
|