Create a text file with your text editor to enter in the code for your PHP script.
Type the PHP code in the text file that will read and store the email form data (the message and the email address that is entered into the Flash Sendmail form) that is sent from Flash.
<?php
$emailaddress = $_POST["recipient"];
$message2 = $_POST["message1"];
$subject = "Email From A Flash Fan";
$send_mail= @mail( $emailaddress, $subject, $message2 );
?>
The PHP script above reads the email address and the message typed into the Flash Sendmail form (the content in the variables named "recipient" and "message1") and stores them in PHP variables named "emailaddress" and "message2." The PHP "subject" variable is used to automatically assign the text "Email From A Flash Fan" to the the subject textbox in the actual email form. The "@mail" PHP function is used to send the contents of the "subject" and "message2" PHP variables to the inbox at the email address stored in the "emailaddress" PHP variable.
Save your PHP file as "lesson_email_flash_sendmailform.php" and upload it to the main directory of your website.
Start the Flash program. Click "Flash File(ActionScript 3.0)" from the splash window to create a new file for the AS3 Flash
Position your mouse cursor on the Flash stage where you want to place the textfield that the email address will be entered into. Press the "T" key on your keyboard to activate the Flash textfield tool. Drag your mouse to set the width and height of the textfield. Click "Properties" from the "Window" menu and type in the instance name "sendTo." Repeat the process to create a textfield that will be used to enter in the email message. Assign this textfield a name of "message_to_send."
Select "Actions" from the "Window" menu on the main Flash menu bar to open the ActionScript 3 editor. Position your mouse cursor on the first line of the ActionScript 3 editor. Click your mouse button, and type in the code below to create a button that when clicked will send the text entered into the email address and message textfields to the PHP file you uploaded to your web site.
var myButton:MovieClip = new MovieClip();
myButton.graphics.lineStyle(4);
myButton.graphics.beginFill(0xFF0000);
myButton.graphics.drawRect(100, 50, 50, 20);
myButton.graphics.endFill();
addChild(myButton);
Type starting at the next line of the ActionScript 3 editor the code to transfer the text entered into the textfields of the sendmail form to the PHP file on your web server. Use a URLVariable object to declare variables to store the contents of the textfields. Use a URLRequest object to store the header information (the name of the PHP file, the actual URLVariables and contents of the URLVariables). Use the Load and POST methods of a URLLoader object to send the contents of the textfields to the PHP file.
var email_variable:URLVariables = new URLVariables();
myButton.addEventListener(MouseEvent.CLICK, callFunction_fn);
function callFunction_fn(e:MouseEvent): void
{
var send_header:URLRequest = new URLRequest("http://www.santa-rosa-algebra-geometry-statistics--tutoring.com/lesson_email_flash_senmailform.php");
send_header.method = URLRequestMethod.POST;
email_variable.recipient = sendTo.text
email_variable.message1 = message_to_send.text
send_header.data = email_variable;
var store_header:URLLoader = new URLLoader;
store_header.load(send_header);
};
The code above declares a URLVariables object. The code is also used to assign an event listener to myButton such that when the button is clicked the instructions contained in the function named "callFunction_fn" are executed. These instructions send the header to the PHP file, which then sends the email to the inbox of the email address specified.
Select "Test Movie" from the "Control" menu. Enter in the email address and the message. Click the "Send" button. Check the inbox of your email to view the email you sent. It will have a subject line of "Email From A Flash Fan."