Flash Contact Form with PHP and Actionscript 2

Posted on July 7, 2009 by Dan Doicaru in Flash Category

In this tutorial you will learn how to create a simple Flash contact form using PHP and Actionscript 2. This flash contact form will have 3 text fields (e-mail, subject and message).

Flash Contact Form in PHP and Actionscript 2

1) Document Settings

First create a new file using Action Script 2.0. Hit CTRL + J (Document Properties) or go to Modify - Document and change your settings like in picture below:


Now we must create only the structure of our flash contact form. We will use the Text Tool (T) and start writing and construct.

First E-mail + Text Field, second Subject + Text Field, third Message + Text Field.

Text Field must be Input Text. We will show you later, now you must have a similar structure like in the picture below:


Now you must set your Text Field with the following settings (click to view larger image)


Now we need a Scroll Bar for Message Field. If someone have a very long message what we can do? Simple.

Go to menu Window - Components (CTRL + F7). On the User Interface rollout you will find UIScrollBar.

Drag and drop it near Message Field and go to Parameters Rollout and near _targetInstanceName write message_field.


2) Drawing the Form Send Button

Good now we must draw a Send button using Rectangle Tool (R) and with Text Tool add a text with "Send".

Select both and press F8 to Convert them to Button and click OK.

Flash Contact Form Send Button

Very good now we must create the Error Message if something is wrong in the flash contact form.

With Text Tool write "All fields required !" and select it, then press F8 and Convert it to MovieClip, and put the instance name "error_clip".


Ok we almost finished with the design and structure of our flash contact form. The only thing left is to create a background for Text Fields.

To do that select Rectangle Tool and draw the same size with a dark color.

  • Border with #555555
  • Background with #222222

The final structure of the flash contact form should look like in the picture below:


3) Coding the Flash Contact Form

Looks nice right? Now we must make the flash contact form work !

Select the first frame and press F9 (Action Script Panel) and insert the code below:


// html-tuts.com - PHP Flash Contact Form
// Loading Variables and Settings
error_clip._alpha = 0;
System.useCodepage = true;
send_btn.onRelease = function() {
	my_vars = new LoadVars();
	my_vars.email = email_field.text;
	my_vars.subject = subject_field.text;
	my_vars.message = message_field.text;

	// If text fields are not blank the message will be sent
	if (my_vars.email != "" and my_vars.subject != "" and my_vars.message != "") {
		my_vars.sendAndLoad("send_mail.php", my_vars, "POST");
	// Else if text fields are blank a warning message will appear
	} else {
		error_clip._alpha = 100;
	// After the message is sent the user will be redirected to frame 3
	my_vars.onLoad = function() {

// If you click on another field "All Fields Required" will dissapear
email_field.onSetFocus = subject_field.onSetFocus = message_field.onSetFocus = function () {
	if (error_clip._alpha != 0) {
		error_clip._alpha = 0;

Go to Timeline and create 2 keyframes by pressing F6.

Select Frame 2 and DELETE ALL except the title and put a text with " Sending Message..." and make a animation.

Select Frame 3 and DELETE ALL execept the title and put a text with " Message Sent. Thank you for contacting us" or any message you want. Press F9 and put stop(); in the Action Script Panel to stop the form playing again.

You should have this:


That's all with Flash ! We need to create the PHP File.

Make the Flash Contact Form Work

Open Notepad or any editor you have and write the code below to make the flash contact form work and send the e-mail with PHP. If you want to know more about mail() function from the last row you can check the documentation here.

// Extreme Design Studio - html-tuts.com
// PHP Flash Contact Form - PHP Script
// Loading Variables
$email = "E-mail: " . $_REQUEST["email"] . "\n\n";
$subject = $_REQUEST["subject"];
$message = "Message: \n---\n" . $_REQUEST["message"] . "\n\n";
$ip = "IP: " . $_SERVER['REMOTE_ADDR'] . "\n";
// The \n character means New Line

// Mixing all variables, including IP
$full_message = $email . $message . $ip;

// Remove the backslashes that appears when entering characters like " or '
$message = stripslashes($message);
$subject = stripslashes($subject);
$sender = stripslashes($sender);

// From and Reply-To Mail Headers
$headers = 'From: Flash Contact Form Test <noreply@example.com>' . "\r\n" . 'Reply-To: Extreme Design Studio <noreply@example.com>' . "\r\n" . 'X-Mailer: PHP/' . phpversion();

// Sending the mail
// Note: Don't forget to change "your@email.com" to receive the mail from contact form
mail("your@email.com", $subject, $full_message, $headers);

Save this file as:  send_mail.php

Important: The .swf and .php file of the flash contact form must be in the same folder!

That's all! Your Flash Contact Form should look like in example below. Enter your email and send a message to yourself to test it!

Live Demo

Download Files

Rate & Share
1 Star2 Stars3 Stars4 Stars5 Stars (10 votes, average: 4.20 out of 5)
Related Articles
  1. Hi

    I need help on my Adobe Flash CS5 website project
    and the version of Action Script 2 so I need help on the contact form
    can you please help me !

  2. Gravatar Icon Bryan Morgan:

    I uploaded the form as specified in the tutorial..but I am not receiving emails. I am using godaddy.com for my hosting and I know that they have php5.2..so I don’t understand why I’m not getting the test emails. Please advise.

  3. Gravatar Icon rob:


    This is a very good tutorial but not for a noob like me. I realized this after some hours of studying :(. Finally I found a nice contact form that is very easy to use. I highly recommend it to all of you who have the same problem as me.

  4. hi,
    I tried the above form it works well in flash but I don\’€™t seem to receive any emails even if I send directly to myself.help pls’€¦

  5. Gravatar Icon MJB:

    Yer I to have done this tutorial word for word. It all seems to work fine, but the message isnt getting sent to my email account. Anyone know why this could be?

    • As I said to everyone, you server needs PHP installed, because the mail() function will not work with your flash application. Also double check the action script code.

  6. Gravatar Icon prempeh:

    I have tested this and it only says sending message and that is as far as it goes. Even when I dont type anything in the fields it is still sending message and not going anywhere.

  7. Gravatar Icon vic:


    I tried the above form it works well in flash but I don\’t seem to receive any emails even if I send directly to myself.help pls…

    • Hello Vic,
      Maybe something is wrong on your flash or server is not supporting the mail function. If you can send me a link to download your files and analyze them, to tell you exactly what is the problem.

  8. Gravatar Icon Adam Walker:

    Hello, very sorry but I agree with a few of the other comments, you need to look at the alpha error message, it’s not working properly, I followed the tutorial in detail.


  9. Gravatar Icon go4urfavour:

    help me out this error-
    Error opening URL ‘file:///D|/send/message_field’

    the “all field required” alpha property not working, it is showing all time…
    and the send button not working, its not navigation to 2nd frame..


  11. Gravatar Icon Dan:

    Excellent thank you. I had to replace all the quotation marks in Flash and in the php file, but it all worked really well. You are a genius!! :-) I am going to check out your other stuff now.

  12. thanks for sharing very nice article..

  13. Gravatar Icon wtf:

    Hi, great tutorial, thank you.
    This is driving me crazy however. I set it all up, it worked perfectly and sent me an email….once. The very first time I tested it it worked. Without changing ANYTHING at all, it no longer sends me any mail. It all functions properly, it just doesnt ever show up in my mail box. I’ve tried 4 different email accounts (aol, google, hotmail, etc) and none of them receive it. What could be the problem?? Thanks!

  14. Gravatar Icon oopz:

    shouldn’t this line in php ($sender = stripslashes($sender);)
    $email = stripslashes($email);

  15. Gravatar Icon shiftingcontrol:

    In the action script code ,we are validating whether mail id is not blank,instead we should check whether the mail id is valid one. . . .

  16. Gravatar Icon cc:

    hello. great tutorial.
    everything seems to work just great… no errors in the codes… the animation shows up just well…
    but it doesn’t send emails.
    i have checked several times, line per line, to see if there was any mistake. but everything is just in the same way you did it.
    if i don’t fill in the fields it, it won’t stop and it won’t show the error clip. it just goes to the 3rd frame with the thank you message.
    that’s all it does.
    and even if i fill in all the fields, the message is not being sent anyway.

    i can’t see where the problem is. any idea? besides from checking the AS or php code again?


    • Yes besides from checking the A.S. or PHP Code again is to check if all the symbols and animations are correctly placed in your frames. After your project will work well you should check your server and see if it supports PHP 5.

  17. hELLOOOO!!

    Thanks for your great Tutorial… Is really well explained…!!!

    Hey I just created my website with Flash and I added your contact form… but is not working. I receive nothing!!! You can check the website at: http://www.novelda-marmol.com

    I don’t know why!!?? This is driving me crazyyyy!! heheh

    I think I just follow the exact same steps as you explained.!

  18. Gravatar Icon Aspect:

    yes. i’ve deleted the text for required field to get rid of it but the emails are not being sent..both are hosted in the same folder but for some reason i’m not recieving the test forms.

    • I saw the contact form on your site. The send_mail.php file is there ? You need the both files to work correctly and you must write the action script and php code corretly. Can you send me all the files in a .zip file ? You will find my e-mail on the contact page. Thank you.

  19. Gravatar Icon Aspect:

    hey, thanks for the tutorial. i’m having the same issues as everyone else it seems. the all fields required section shows up at the beginning and emails don’t get sent. it also seems that you have to tab down to the send button. if you try to just click it it selects text. any help with this? thanks.

  20. Gravatar Icon Sanjay:

    i don’t idea about how i create php form for my website with spam protection. Current i am using php form from emailmeform but i need my own php form code. Please tell me or suggest me how i create php form to i use for my all website. I am waiting for kind suggestions…

  21. Gravatar Icon Carolina:

    Hi there, your tutorial is GREAT!

    The only problem is that the alfa=0 property fot the Movie Clip “error_clip”” is not working.

    The text shows on my form and if I leave a field black and click Send nothing happen.

    The text “All fields Required” is a Moviel Clip with an instancename error_clip.

    Thanks a lot

  22. Gravatar Icon nextoshine:

    Simply the Best you done for Us…
    EDS you Rock!

  23. Gravatar Icon Chris:

    I have the same problem as many others of the e-mail not getting to my inbox. Everything works great except I am not receiving any e-mails. I have read the above replies saying:

    This problem is maybe from your server (mail function not supported or not installed) or you didn’€™t followed all the steps carefully.

    How can I find out if it is supported and/or where can I get the proper installation so that this will work?

    • Hello Chris. This contact form should be uploaded on a web server with PHP 4.0 or later with mail() function active. You should ask your hosting provider if you have all these options.
      One other problem is the wrong action script code or php code and verify your file names to be written correctly! If you still have problems you can contact via this form.
      Thank you for your comment.

  24. Gravatar Icon emma:

    Hi great tutorial, Just one question, how do you add extra fields?

  25. Gravatar Icon Kaska:

    I have a problem with the flash form,…

    When I resive it,… say anonymous and the server address,….

    how can I put the info “FROM” to get the name or email data ???

    Thnx for the time to read .

    i´llwait for the answer.

    c YA

  26. Gravatar Icon Art:

    I have the same problem … did’nt get any e-mail in my mail box after all …
    Using CS3 and AS2 … just changed e-mail in send_mail.php and upload it to server to test it
    And nothing …

  27. Gravatar Icon noah:

    i made this, and tested it, and nothing is happening.. i do not get e-mails in my in-box..

  28. Gravatar Icon Andy:

    Thas is cool , good tutorial

  29. Gravatar Icon rawr:

    I use Hostgator and I’m pretty sure they support all email methods. I had a regular php one that worked fine, it’s just I didn’t have the time to make it work right with what I was doing. So I went flash as I thought it may be easier. Is there anyone someone can give me a code snippet with this form that includes a name field that works? It would be appreciated.

  30. Gravatar Icon Simpson:

    i followed your directions exactly and i got this error

    1084: Syntax error: expecting rightparen before and.

  31. Gravatar Icon Kevin:

    So, how can I do e-mail validation?

  32. Gravatar Icon Shin:

    i copy your action script to flash, but running error, why?

  33. Gravatar Icon rawr:

    I’m having problems with it even sending emails. I added one form of my own (name) and it doesn’t seem to send any emails at all.

  34. Gravatar Icon v3nil:

    @ Qing Ling:

    You can very well use this to save the emails in a database.
    You need to know a bit of php and mysql(for db) and your problem is solved.
    I would like to help you.
    you can contact me at venil4u@gmail.com

  35. Gravatar Icon Qing Ling:

    Hi, i would like to ask if the email send with be store in database??
    And i wanted it to store in database, is it possible??
    Thanks. Your help is greatly appreciated..

    • E-mails are not stored in any kind of database. The flash file is using the action script to send the code in the PHP file. After that the message is sent.

Hint: Wrap your code syntax (html, css or others) between <pre> and </pre> tags. All comments are moderated.

9 + = 16

Subscribe by E-mail

HTML-TUTS is created and maintained by Dan Doicaru.
This website is a rebrand to Extreme Design Studio (extremestudio.ro), built under WordPress platform.