Update: Flash is more or less a dying technology, I'd strongly recommend looking into using a JavaScript alternative.

Learning how to interact with server-side controls from Flash is very useful. Flash can make a GUI look interactive, awesome, and elegant. Server side controls can persist data, send emails, and do other powerful things. Tying the two together can make magical things happen.

The URLRequest and URLLoader that ActionScript supplies makes calling a server side control easy as pie. I mention in the video, or at least attempt to mention, the URL the flash application is accessing/sending data to needs to be on the same domain that the flash application is on. This is for security reasons.

Below is the code I promised - 100% working. It would be awesome to add some effects on the flash form. Like once the mail gets sent; have a big monster come and pulverize the text inputs rendering them useless.

Flash Class:

package {
	
	import flash.display.MovieClip;
	import fl.controls.Button;
	import fl.controls.TextInput;
	import fl.controls.TextArea;
	import fl.controls.Label;
	import flash.net.URLRequest;
	import flash.net.URLVariables;
	import flash.net.URLLoader;
	import flash.net.URLRequestMethod;
	import flash.events.IOErrorEvent;
	import flash.events.MouseEvent;
	import flash.events.Event;
	
	public class MailScript extends MovieClip {
		
		private var submit:Button;
		private var theName:TextInput;
		private var theEmail:TextInput;
		private var theComment:TextArea;
		private var nameLabel:Label;
		private var emailLabel:Label;
		private var commentLabel:Label;
		private var successLabel:Label
		
		public function MailScript() {
			buildControls();
		}
		
		private function sendMail(e:MouseEvent):void {
			var url:String = "http://www.robkeplin.com/sendMailTest.php";
			var request:URLRequest = new URLRequest(url);
			var variables:URLVariables = new URLVariables();
			variables.senderName = theName.text;
			variables.senderEmail = theEmail.text;
			variables.senderComment = theComment.text;
			request.data = variables;
			request.method = URLRequestMethod.POST;
			
			var loader:URLLoader = new URLLoader();
			try {
				loader.load(request);
			} catch(e:SecurityError) {
				trace("Security Error...");
			}
			
			loader.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
			loader.addEventListener(Event.COMPLETE, successHandler);
		}
		
		private function successHandler(e:Event):void {
			try {
				trace(e.currentTarget.data);
				if(e.currentTarget.data == "1") {
					submit.removeEventListener(MouseEvent.CLICK, sendMail);
					successLabel.text = "Successfully Sent Mail!";
				} else if(e.currentTarget.data == "3") {
					successLabel.text = "Error - Email Must Be Valid!";
				} else if(e.currentTarget.data == "4") {
					successLabel.text = "All fields are required!";
				} else {
					successLabel.text = "Sorry, Unable to Send Mail... :(";
				}
			} catch(error:TypeError) {
				trace("Error getting loader data");
			}
		}
		
		private function errorHandler(e:IOErrorEvent):void {
			trace("Whoopsies, problem loading the page...");
		}
		
		private function buildControls():void {
			submit = new Button();
			theName = new TextInput();
			theEmail = new TextInput();
			theComment = new TextArea();
			nameLabel = new Label();
			emailLabel = new Label();
			commentLabel = new Label();
			successLabel = new Label();
			
			submit.x = 100;
			successLabel.x = 200;
			theName.x = 100;
			theEmail.x = 100;
			emailLabel.x = 30;
			theComment.x = 100;
			nameLabel.x = 30;
			commentLabel.x = 30;
			
			theName.y = 17;
			nameLabel.y = 17;
			theEmail.y = 45;
			emailLabel.y = 45;
			theComment.y = 75;
			commentLabel.y = 75;
			submit.y = 180;
			successLabel.y = 180;
			
			theName.width = 200;
			theEmail.width = 200;
			theComment.width = 300;
			theComment.height = 100;
			
			nameLabel.text = "Name: ";
			emailLabel.text = "Email: ";
			commentLabel.text = "Comment: ";
			submit.label = "Send!";
			successLabel.text = "";
			successLabel.autoSize = "left";
			
			submit.addEventListener(MouseEvent.CLICK, sendMail);
			
			addChild(submit);
			addChild(theName);
			addChild(theEmail);
			addChild(theComment);
			addChild(nameLabel);
			addChild(emailLabel);
			addChild(commentLabel);
			addChild(successLabel);
		}
	}
}

The PHP processing page:

<?php
/**
 * @author Rob Keplin
 * @copyright 2009
 */

if($_POST['senderName'] && $_POST['senderComment'] && $_POST['senderEmail']) {
	
	if(preg_match("/^[a-zA-Z0-9-._]+@[a-zA-Z0-9-._]+.(com|org|net|mil|edu)/", $_POST['senderEmail']))
	{
		$recipient = "your-email@example.com";
		$message = nl2br($_POST['senderComment']);
		$message .= "rnFrom: " . $_POST['senderName'];
		$subject = "From My Flash App!";
		$headers = "From: " . $_POST['senderEmail'];
		
		if(mail($recipient, $subject, $message, $headers)) {
			echo "1"; //Success
		} else {
			echo "2"; //Failed Sending Mail
		}
	} else {
		echo "3"; //Invalid Email
	}
	
} else {
	echo "4"; // All Fields Required
}
?>