Search
Recommended Sites
Related Links






   

Informative Articles

6 Easy Ways to Create a Website
Creating a website is not as hard as you think it is. In fact you can do it in 6 easy steps. How? Here it is... 1. Conceptualize an idea. Think what you like your future website to be. What audience will you cater? Everything you...

Nvu Review
Ongoing growth in the availability of strong open source applications encourage keeping an eye out for Open Source alternatives to commercial applications. With the release of Nvu there is a potential alternative to FrontPage, GoLive and...

Some Online Tools to Make a Mark on Internet
If you are simply dreaming of "having" a Website. It's okay..... But if you are keen on "making" your own mark in the Web, and really interested in authoring it, brand it with your very own style and technique, there are some online tools for you to...

YOUR FIRST HTML PAGE - II
In the book, "The Agony and the Ecstasy", I read that Michael Angelo dug up graves in order to study the human anatomy in all its gory manifestation. He used to hold the internal organs in his bare hands. He came up with masterpieces. The same is...

YOUR FIRST HTML PAGE - V
Tables are used to display information in an orderly manner. Incidentally, here we are not talking furniture. A table means tabular representation of certain data on your computer screen or in printed form. == Step 8: == Ideally, a table consists...

 
PHP Form Mail Script

A Very simple PHP form processor that goes with the HTML form I created in the HTML forum.
<HTML> <HEAD> <TITLE>Thank You</TITLE> </HEAD> <BODY>
<?php
$date = date ("m/d/Y");
$name=$_POST['name']; $email=$_POST['email']; $comments=$_POST['comments'];
$to="youremail@yourdomain.com"; $subject="The subject for your email"; /* IE: Comments on $date */ $message="Comments from $name\n\nName: $name\nE-mail: $email\nComments: $comments"; $from="$email"; $headers="From: $email\n";
if (mail($to,$subject,$message,$headers)) { echo "<CENTER>Thank you for sending your comments</CENTER>"; } else { echo "There was a problem sending mail, this is a coding issue"; }
?>
</BODY> </HTML>
Lets get go through the explanation of this. You'll notice that I included the HTML tags as it's a good practice to get into. Most of you know how to begin a PHP statement by using <? and ending it with ?>, that's fairly simple.
$date = date ("m/d/Y");
This line configures the date, I enjoy using this and putting it somewhere in the processor, mainly the subject, so I know what date the comments were sent in on. This can be configured many different ways.
$name=$_POST['name']; $email=$_POST['email']; $comments=$_POST['comments'];
These three statements are how you get the information from the HTML form into this PHP processor. This takes from the POST method the HTML form and assigns the output into variables that we can use to produce the output. These output variables can differ depending on the info that your forms provide.
$to="youremail@yourdomain.com"; $subject="The subject for your email"; /* IE: Comments on $date */ $message="Comments from $name\n\nName: $name\nE-mail: $email\nComments: $comments"; $from="$email"; $headers="From: $email\n";
This is all the information to actually output the information. $to is the email address that you wish to send the comments to. $subject is the subject of the email that gets sent. $message is the formatted message that will be the body of the message with the variables, Note: \n skips 1 line. $from is the email address it's coming from, which isn't necessarily needed. $headers creates the headers for the email message, you should make it good attempt to do so, as some mail servers won't accept the mail without headers.
if (mail($to,$subject,$message,$headers)) { echo "<CENTER>Thank you for sending your comments</CENTER>"; } else { echo "There was a problem sending mail, this is a coding issue"; }
This is the piece of code that actually sends the email. PHP has a very simple command to send mail it's mail($to,$subject,$message,$headers); and is very self explanatory, as it mails using those variables. The if statement allows coding error control. If the email address entered isn't correct, or something is missing, it will post an error.
That concludes this PHP form mail tutorial. Please visit http://justincanada.net for more :). Thanks.
About the Author
Justin Robinson http://justincanada.net

Sign up for PayPal and start accepting credit card payments instantly.