I’ve just created a little sample for a friend. He is a designer and “just needed something” that would allow him to capture the data that users enter. FormMail.cgi fits the bill – no need to touch any server files or databases, just point your Flash to a FormMail script that is already installed on your server and off you go – you are sending emails from Flash. It feels bit 90-ies, but it works.

What will you need:

  1. Flash CS3 or newer (download free 30 days trial from Adobe)
  2. URL to FormMail.cgi. Many hosting providers have installed FormMail.cgi for you – you will definitely have it if you have cPanel, look under Scripts to find the right path to yours. Otherwise ask your hosting provider or pinch somebody else’s FormMail (not recommended :-) ).

Here are instructions that any Flash designer should be able to follow:

  1. Create a AS3 Flash document.
  2. Create your text inputs. My code is using 3 Text Inputs named: messageTI, nameTI, emailTI. You can create more, or rename them, but then you will have to add/modify the code a little bit.
  3. Create a button and name it sendB
  4. Create a dynamic text and name it statusTF
  5. Create an Actions layer and in the first frame put the following code, than modify the FormMail URL and recipient’s email:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import flash.events.MouseEvent;
import flash.profiler.showRedrawRegions;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;

sendB.addEventListener(MouseEvent.CLICK, sendData);

function sendData(e:MouseEvent):void {
    if (messageTI.text.length > 3 && nameTI.text.length > 3 && emailTI.text.indexOf("@") > -1) { //very, very basic data validation (as this is not a data validation tutorial)
        var r:URLRequest = new URLRequest("http://YOUR-URL-TO-FORM-MAIL/FormMail.cgi"); //modify this URL
        var v:URLVariables = new URLVariables();
        v.recipient = "YOUR-EMAIL@DOMAIN.com"; //put your email here
        v.subject = "My FormMail test"; //this will be the subject of the email
        v.email = emailTI.text;
        v.realname = nameTI.text; //user's name will be appended to his/hers email to form a From field of the email.
        v.theMessage = messageTI.text; //theMessage is a custom key. If you need more Input fields, just make up more custom fields like this one
        r.data = v;

        r.method = URLRequestMethod.POST;
       
        var loader:URLLoader = new URLLoader();
        loader.addEventListener(Event.COMPLETE, completeHandler);
        try {
            loader.load(r);
        } catch (error:Error) {
            statusTF.text = "Unable to send data."; //we could definitely do more in terms of error handling, however this is not a error handling tutorial
        }
    } else {
        statusTF.text = "Please enter all required information.";
    }
}

function completeHandler(event:Event):void {
    statusTF.text = "Data submitted.";
    var loader:URLLoader = URLLoader(event.target);
    trace("completeHandler: " + loader.data);
}

Notes:

  1. You can place your components (Button, TextInputs & Dynamic Text) anywhere you like on a page, style them anyhow you like, but make sure they are in the first frame and have the correct names (case sensitive).
  2. If email is getting send but you are not receiving any – check your spam folder.
  3. You are too lazy to copy/paste? I hear you. Here is the sample flash file.