First time here? First time here? Newsletter Signup Newsletter
Login | Register | 651326 Members and growing!
Search tutorials
Author: Jeffrey F. Hill | Website: http://www.flash-db.com

Part II - Setting up the server scripts

 Note: I have included three options in this tutorial - PHP, Perl, and ASP - You only need to use one.  This mainly depends on what type of server that you are using, and what is available on that server.  For Unix/Apache based servers, the Perl and PHP ones will work - with Perl being a little more universal.  For win NT/2000 servers the ASP and Perl scripts will work - some modifications will have to be made to the Perl script however.  To find out what type of server you are using and what scripting languages you have available for use, either view the documentation provided by your host, or call your server's tech support.  

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. 

Note:  The User Entered variables in this case / example are - FirstName, Email, Company, ToComments, HearAbout - These values are from the flash movie.  No special parsing is required in PHP if it receives these variables then they are already set inside the script.  You may also want to add the stripslashes function in this script if you don't want slashes to be added to your output. An example of how to do this would be: $ToComments = stripslashes($ToComments);  
1)  <&quest

2)  $ToEmail = "jeff@snowvids.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

Added: 2001-08-27
Rating: 9 Votes: 328
(10 being the highest)
» Author
No details available.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!

Comments

  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: Inocreato
» Title: RaiseTheBlocks
» Description: Raise all the blocks to win the game
Featured Sound Loops
Image for equalize

Audio Player

» Author: TomCat Carty
» Title: The Wood
» Description: Just a little game ending or it can maybe be looped. Recorders with music box and percussion to give the feel of well, I don't know, the woods? Free to use, just credit me. thank you
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: Davisigner
» Description: Hmm... what to say about this one? It's reminiscent of the closing notes of the opening music from the Three Stooges done in a church organ style with a closing cymbal crash. I'll give this one away gratis, but feel free to check out my free loops and potential upcoming license-mandated ones over in the respective part of Flashkit.