Part II - Setting up the server scripts
One thing to remember is that these script examples were written as educational examples, with simplicity and ease of use in mind. They all work and can be immediately used, but extra security precautions should be taken if you are planning to use these scripts extensively on a public website, and have any reason to believe that someone would take advantage of them.
Option 1 - Setting up the PHP Script - to send mail with PHP
The PHP option remains my favorite, it is easier to set up then the rest and PHP in general is easier to learn and understand for this type of application (Opinion). Your server has to have either PHP 3 or 4 installed to be able to use the following.
The Code is listed below - each line of the code is then discussed. Line numbers should not be included in the Actual script. This script is also included with the download. After you have made any changes, upload the script to the same directory that you will be running the Flash movie that contains the Mail form. If you have the script in a different directory you will have to change the path in the loadvariables command (Send Mail Button)). Note: The $ symbol in PHP indicates a scaler variable.
1) <&quest 2) $ToEmail = "email@example.com"; 3) $ToName = "Jeff"; 4) $ToSubject = "Example Mail from SendMail Tutorial"; 5) $EmailBody = "Sent By: $FirstName\nSenders Email: $Email\nSenders Company: $Company\n\n Message Sent:\n$ToComments\n\nSender Heard About Site From: $HearAbout\n"; 6) $EmailFooter="\nThis message was sent by: $FirstName from $REMOTE_ADDR If you feel that you recieved this e-mail by accident please contact us at www.yourSite.com"; 7) $Message = $EmailBody.$EmailFooter; 8) mail($ToName." <".$ToEmail.">",$ToSubject, $Message, "From: ".$FirstName." <".$Email.">"); 9) Print "_root.Mail.EmailStatus=Complete - Your mail has been sent"; 10) &quest>
Open up the attached script called snowMailPHP.php and follow along - you can use any text editor to make any changes.
Line 1: This just indicates the start of a php script. In some cases it can be
Line 2: This is one of the most important lines - this contains the e-mail address of the person that you want the message sent to. In most cases this will be your own e-mail address. I left it as my own for now - Be sure to change this to Your e-mail address.
Line 3: This Line contains the Name of the person that you are sending this E-mail to. In most cases you will hard code that into the script here, as shown. You can also set this variable as a hidden variable in the Flash movie. When you use the 'Post command' in conjunction with this script, the hidden variable will be sent along with the other variable values.
Line 4: This Line sets the Subject line of the e-mail that you are sending.
Line 5: This line combines the variables that were sent to the script by the 'Post command' when you used load variables from the Flash movie. This is where you can format the look of your e-mail.
Line 6: This adds some additional information to the bottom of the e-mail that you are sending. You can add any extra info you want here. Make sure to remember that everything has to be enclosed with " symbols and a ; symbol has to end the line. Also note that the \n combo adds a return/new line to your e-mail.
Line 7: This just combines the variables $EmailBody and $EmailFooter into one variable $Message.
Line 8: This line is what actually sends the E-mail. The php Function Mail is what does the job. By enclosing the E-mail tags within <> symbols it creates something like a mailto function. That way the person can respond to the e-mail directly.
Line 9: This prints a message back to the flash movie. In this case it sets the variable EmailStatus contained in the movie clip instance of Mail to a value of " Complete - Your mail has been sent".
Line 10: This just signifies the end of the PHP code.
Well those are the basic's of what you need to know to send mail from a form in Flash with PHP. I hope that wasn't too confusing.
|» Level Advanced|
Rating: 9 Votes: 328
|No details available.|
|Download the files used in this tutorial.|
|Download (67 kb)|
|More help? Search our boards for quick answers!|