|
LiveMotion Forms - Part V
Setting up our PHP Script.
Setting up the PHP script will be easier then the ASP and CFML examples. This is one of the reasons that PHP is a popular language. It is extremely simple to understand and impliment. Our PHP code will be a whopping 9 lines of code to enter. Copy this code to a new text file and name it lmcMail.php
Again, remember to remove the line numbers before running your
code.
--- CODE ---
00<?php
01$ToEmail = "You@yourdomain.com";
02$ToName = "Your Name";
03$ToSubject = "Your Subject";
04$EmailBody = "Message from LM2 / PHP Form\n\nName: $txtName\nEmail: $txtEmail\nURL: $txtURL\nComments:\n$txtComments";
05$EmailFooter = "\n\nMessage Complete";
06$Message = $EmailBody.$EmailFooter;
07mail($ToEmail, $ToSubject, $Message, "From: $txtEmail");
08Print "_root.form.txtStatus=Complete - Your mail has been sent!";
09?>
--- CODE ---
Line 00: Starts our PHP Code Block
Line 01: Enter in your email between the quotes.
Line 02: Enter in your name between the quotes.
Line 03: Enter in the subject you want to use between the quotes.
Line 04: This is the Email Body String. Notice that the entire string is in a single pair of quotes. The \n is like a JavaScript Line Feed or New line. It is a BREAK and not a Paragraph. So to make a paragraph, you will need to use two in a row like this \n\n. As well, to CALL a variable from the form we have made, you will need to use the $fieldName. So to display a field name in our body, we want to put in the email, what the field name is, and then shows it's value. Like this; Name: $txtName That will display Name: Entered Name, where entered name is the name your visitor enters in the Name field.
Line 05: This is the Message Footer, which will appear at the BOTTOM of our message. Here we simply add two new lines, and write Message Complete.
Line 06: Message will call the two Variable Names EmailBody and EmailFooter and write them in the Message.
Line 07: Here we actually build the entire email message. The To: Subject: Message: and From are all setup.
Line 08: Here we write a message back to the flash file to tell the user that the message has been sent.
Line 09: We close our PHP Code Block.
If your only doing the PHP script, skip to the end of this tutorial
part
1
2
3
4
5
6
|