PDA

View Full Version : Email In Flash



mikel_26
May 7th, 2008, 08:04 AM
:-/

snickelfritz
May 7th, 2008, 11:40 AM
On the stage in frame1, on it's own layer:
input text field, instance name "fullName_txt"
input text field, instance name "email_txt"
input text field, instance name "subject_txt"
input text field, instance name "message_txt"
Button Component, labeled "submit", with instance name "submit"

Give frame2 the frame label "submit", and place a stop(); command on the actions layer in that frame.
Place a Dynamic Text field on the stage in frame2, and type a message to the sender in it.
ie: "thanks for sending me an email" or something like that.

Paste the following actionscript 3.0 on a locked "actions" layer of the timeline.

stop();
pageLoad();

//form handler
var variables:URLVariables = new URLVariables();
var varSend:URLRequest = new URLRequest("sendmail.php");
var varLoader:URLLoader = new URLLoader;
varSend.method = URLRequestMethod.POST;
varSend.data = variables;

submit.addEventListener(MouseEvent.CLICK, sendActions, false, 0, true);

function sendActions(event:MouseEvent):void {
variables.fullName = fullName_txt.text;
variables.email = email_txt.text;
variables.subject = subject_txt.text;
variables.message = message_txt.text;
varLoader.load(varSend);
play(); // playhead will move forward to the stop action on frame label "submit".
}

Paste the following PHP code into a new plain text document, and name it "sendmail.php".
Save this document in the same folder as your swf.

<?php

//edit this to be your email address.
$destinationAdress="yourEmail@yourHost.com";

$nowDay=date("d.m.Y");
$nowTime=date("H:i:s");

$fullName = $_POST['fullName'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];

$FormContent="Message date = $nowDay at $nowTime
----------------------------------------------------------------------------
From: $fullName
Email: $email
Subject: $subject
----------------------------------------------------------------------------
Message: $message
";

mail($destinationAdress, "$subject [ from $fullName ]", $FormContent, "From: $email");

?>

mikel_26
May 8th, 2008, 06:23 AM
:)

Dimitree
May 8th, 2008, 07:22 AM
no, you have to upload all the files swf, php to the server and test it on line. It wont work unless you have localhost which I guess you havent. Then upload the files to your website and test it!

mikel_26
May 9th, 2008, 09:08 AM
:)

mikel_26
May 9th, 2008, 09:28 AM
:)

monkeyhead
May 9th, 2008, 09:43 AM
this is the listener on the "submit" that calls the function:

submit.addEventListener(MouseEvent.CLICK, sendActions, false, 0, true);

just drag and drop the files to your ftp...

NOTE:
i had an issue before where my server didnt have php installed. If this is the case with you, those files will not work.

mikel_26
May 9th, 2008, 09:48 AM
:)

ThaJock
May 9th, 2008, 11:51 AM
Mikel_26:

First of all I'm not as good with flash as most of these guys and gals but I was in the same boat as you for several days and finally found a simple solution.

For this you need two frames. Place a stop action on both frames.

I assume you already have your form on frame 1 with your input text fields with variable names and a send button. In this example I have 3 input text fields name, email, and message. Just select each input text field while holding shift so that you can select them all and convert them to a movie clip with an instance name of "form". Make sure you have a stop action on frame

Click on the send button and add this script to it:

on (release) {
form.loadVariables("form.php", "POST");
form.onData = function() {
nextFrame();
};
}

Create a new keyframe on frame 2 and design whatever you want the user to see after they have the send button. Example : Thank You
That's it for the flash side of it. Just export the swf. Now on the PHP side....

The php code looks like this:

<?

$Name = $_POST['name'];
$Email = "your@email.com";
$Message = $_POST['message'];
$Subject = "Your Subject Here";
$Header = "From: $Name <$Email>";

mail($Email, $Subject, $Message, $Header);

?>

Replace "your@email.com" with your email address and
Replace "Your Subject Here" with your subject (keep the quotations).
Save this as form.php and don't forget the .php extension

Make sure your swf and php file is in the same folder on your server and it should work.

monkeyhead
May 9th, 2008, 03:29 PM
that will never work with AS3

snickelfritz
May 9th, 2008, 04:36 PM
Ok it didnt go "ON" i mean this is the way i did so just please correct me if i am wrong ?

on the upload site

the following file's will be uploaded,

swf file

php file

done all the editting of codes

etc...

upload

done....

when i view the html a.k.a "website"

try the flash ?

ta dah !

no email.... ?

SWT...

XD !

There are 4 files to upload to your server.
AC_RunActiveContent.js
index.html
flash_movie.swf
sendmail.php

Felixz
May 9th, 2008, 06:23 PM
All works perfectlythat php file when left unchanged has 666 bytes total :)