Search
Recommended Sites
Related Links






   

Informative Articles

Choosing Components For Deck Railing Plans
A deck railing component is very important in creating the deck railing plan that will offer your deck its finishing touches. There are a number of different components in creating the perfect deck railing. One deck ...

Front-end Web Developer Metamorphosis
The only constant thing in this world is change. You have to be adept with these changes in order to keep going and excel. Web design is not the be-all end-all in developing a site. This is the very reason why metamorphosis has led...

Observing the Protocols: HTTP, WWW, URL and HTML
Many among us sail through our lives blissfully ignorant of the reason our web addresses start with the secret code "http//:" Increasingly we think it is superfluous because when we omit entering it into the address line of our browser, usually we...

Stop Driving Your Visitors Away!
Your web site may contain flaws or glitches that are driving your visitors away! Such a thought is enough to give the most laid back webmaster a migraine. How can you uncover and fix any problem areas that may be lurking in the dark recesses of...

You CAN Create A Web Site Without HTML
When I decided to start BizyBodies.com web site, one of my biggest problems was the thought of having to learn HTML, Hypertext Markup Language, the code used for creating all of the information you see on the web pages. I don't know about you,...

 
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.