E-mail Flash Form with PHP3

kennbona

New Member
Messages
27
Reaction score
0
Points
0
hi, I'm currently working on a flash Contact Us Form for my website. I tried Following a tutorial but so far no luck.

There are basically two files, The flash.swf "form" and the mail.php3 file.

this is the code i have used:
PHP3
Code:
<?php
 mail("smartwebsolutions@mail.com", $_GET["first_name"], $_GET["last_name"], $_GET["address"], $_GET["town"], $_GET["telephone"], $_GET["mail"], $_GET["business_name"], $_GET["business_type"], $_GET["app_date"], $_GET["comments"], "From: PHPMailer
Reply-To: $_GET["from"]
X-Mailer: PHP/" . phpversion());
 ?>

This is the ActionScript i used:
Code:
Send_Form.onRelease = function()
{    
        var first_name:String = First_Name.text;
        var last_name:String = Last_Name.text;
        var address:String = Address.text;
        var telephone:String = Telephone.text;
        var mail:String = E_Mail.text;
        var business_name:String = Business_Name.text;
        var business_typs:String = Business_Typs.text;
        var app_date:String = App_Date.text;
        var comments:String = Comments.text;
        errmsg.text = "Please wait... Connecting";
        lineAdapt();
        loadVariablesNum("mail.php3", 0, "POST");
        gotoAndStop(3);
}

Basically frame 3 has a simple E-mail sent message.
and i also have this:
Code:
function lineAdapt () 
{
    message_send = message;
     while (msg_count<length(message)) 
    {
        msg_count = msg_count+1;
          if ((substring(message_send, msg_count, 2)) eq "") 
          {
              message_send = (substring(message_send, 1, msg_count-2))+ "" +(substring(message_send, msg_count+2,(length(message_send))-msg_count+2));
          }
     }
     message = message_send;
     delete msg_count;
     delete message_send;
}

this is where i got the tutorial and most f the code from : http://www.actionscript.org/resources/articles/82/2/Send-Email-via-Flash-and-PHP/Page2.html
Obviously i tried complicating mine beyond my level..
I hope someone can help me understand what i'm doing wrong.

Thanks in advance
Kenneth Bonanno
 

tittat

Active Member
Messages
2,478
Reaction score
1
Points
38
Tutorials section is only for teaching and learning how to do things on the internet.
This sort of questions should be on Programing help.
*****Thread Moved to Programming Help*****
 

kennbona

New Member
Messages
27
Reaction score
0
Points
0
ye sorry for that, only realized after i posted it..

so, any ideas anyone? It's really frustrating when you have something in your mind but you lack the experience or knowledge to make it work.
 

xav0989

Community Public Relation
Community Support
Messages
4,467
Reaction score
95
Points
0
Well first of all, php3 is not supported anymore, so you could try to find one using php5
 

FengFeng

New Member
Messages
59
Reaction score
0
Points
0
what verison of action scripts do u use?
Edit:
I think the problem is in your AS code.It isn't so easy to post request in flash.You can use this php5 code to check the request.

<?php
print_r($_POST[]);
?>

If you get nothing,it's the AS issue.Otherwise,it's the php issue.It's easy to mail in x10hosting,becasue it support the mail function.You can search many info abt mail() in php5.
 
Last edited:

kennbona

New Member
Messages
27
Reaction score
0
Points
0
ok, i just scrapped my old form.. And followed a video tutorial and i did everything step by step.. identical to the tutorial... I managed to receive the e-mail.. but The variables couldn't be read... so i'm getting this:

Name:
Email:

Message:

this is the php code that i used:

PHP:
<?PHP

$to = "***********@mail.com";
$subject = "Flash contact Form";
$message = "Name: " . $theName;
$message .= "\nEmail: " . $theEmail;
$message .= "\n\nMessage: " . $theMessage;
$headers = "From: $theEmail";
$headers .= "\nReply-To: $theEmail";

$sentOk = mail($to,$subject,$message,$headers);

echo "sentOk" . $sentOk;

?>


and this is the AS code.. btw using AS2

Code:
stop();

var senderLoad:LoadVars = new LoadVars();
var receiveLoad:LoadVars = new LoadVars();

sender.onRelease = function() {
	senderLoad.theName = theName.text;
	senderLoad.theEmail = theEmail.text;
	senderLoad.theMessage = theMessage.text;
	senderLoad.sendAndLoad("http://www.**************.com/send.php",receiveLoad);
}

receiveLoad.onLoad = function() {
	if(this.sentOk) {
		_root.gotoAndStop("success");
	}
	else {
		_root.gotoAndStop("failed");
	}
}
 
Last edited:

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
As of PHP 4.2.0, register_globals is off by default, which means you need to reference $_GET, $_POST or $_REQUEST to get the form variables. I prefer $_REQUEST so that I may change the submission method/use different methods. Others prefer using $_POST under the (mistaken) belief that it's more secure.

Read "Variables from External Sources" for more information on form variables.

Since the form handler isn't printing HTML, you'd better put a header('Content-type: text/plain') line in the script, somewhere before you print any other output.

Before you get too far into this, what's the reason you're using Flash? If you're doing this as a learning experience, or you're writing a Flex application, that's one thing, but for a web form, Flash is a poor choice when it comes to accessibility. Screen readers and many cell phones don't support flash.
 
Last edited:

kennbona

New Member
Messages
27
Reaction score
0
Points
0
thanks for your reply mission,
I know flash is not the best option to use for online forms, but a friend of mine needs to have
this think made of flash,... tried to give him other alternatives but he's just interested.

going to give this a try.. however i not familiar with php at all.. so please gueid me in the right direction..

origional Script:
PHP:
<?PHP

$to = "smartwebsolutions@mail.com";
$subject = "Flash contact Form";
$message = "Name: " . $theName;
$message .= "\nEmail: " . $theEmail;
$message .= "\n\nMessage: " . $theMessage;
$headers = "From: $theEmail";
$headers .= "\nReply-To: $theEmail";

$sentOk = mail($to,$subject,$message,$headers);

echo "sentOk" . $sentOk;

?>

should i change the only one where it says echo? what about the others like $message and $headers?

so something like this?:
PHP:
<?PHP

header('Content-type: text/plain');
$to = "smartwebsolutions@mail.com";
$subject = "Flash contact Form";
$message = "Name: " . $_REQUEST['$theName'];
$message .= "\nEmail: " .$_REQUEST[' $theEmail'];
$message .= "\n\nMessage: " . $_REQUEST['$theMessage'];
$headers = "From: " . $_REQUEST['$theEmail'];
$headers .= "\nReply-To:" . $_REQUEST['$theEmail'];

$sentOk = mail($_REQUEST['$to,$subject,$message,$headers']);

echo "sentOk" . $_REQUEST['$sentOk'];

?>
 

ziyadg

New Member
Messages
2
Reaction score
0
Points
0
Try these

PHP:
<?PHP

$theName = $_POST['theName'];
$theEmail = $_POST['theEmail'];
$theMessage = $_POST['theMessage'];


$to = "smartwebsolutions@mail.com";
$subject = "Flash contact Form";
$message = "Name: " . $theName;
$message .= "\nEmail: " . $theEmail;
$message .= "\n\nMessage: " . $theMessage;
$headers = "From: $theEmail";
$headers .= "\nReply-To: $theEmail";

$sentOk = mail($to,$subject,$message,$headers);

if($sentOk) {
    echo "status=Message Sent!";
} else {
    echo "status=Sending Failed.";
}

?>
Code:
// AS2

var loadVars:LoadVars = new LoadVars();
var responseHandler:LoadVars = new LoadVars();
loadVars.theName = "Name";
loadVars.theEmail = "Email";
loadVars.theMessage = "The Message";

loadVars.sendAndLoad("myphpfile.php", responseHandler, "POST");

responseHandler.onLoad = function() {
    status.text = responseHandler.status;
}
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
thanks for your reply mission,
I know flash is not the best option to use for online forms, but a friend of mine needs to have
this think made of flash,... tried to give him other alternatives but he's just interested.

Does he really need a flash form or does he just want one? Wanting a flash form merely because it looks good (if that's why he wants one) is a poor reason. Talk to him about usability and accessibility, which are much more important than visual impact when it comes to forms. In any case, using HTML and CSS, you can produce forms that look just as good as any flash based form. Flash's only strength is animation.

PHP:
$_REQUEST['$to,$subject,$message,$headers']
This will look for the value in $_REQUEST with literal key '$to,$subject,$message,$headers'. This is wrong for two reasons. The first is you don't want a literal (e.g.) '$to' in your index, you want the value of variable $to. Use double quotes, not single quotes, to get variable interpolation. Secondly, the comma character is not special in an array index. To get a slice of array elements, use array_slice

ziyadg posted an almost complete solution, but there's one more thing: you can't trust the form input. It's easy for a user to submit anything they want, even if you add client side validation. For this particular form, a visitor could inject headers via the theEmail input. More dangerous, if the mailhost doesn't filter e-mail, a visitor could include a cookie-stealing script (or worse) in the message using a <script> tag. View the message using webmail and you're hacked.

For this form, filter_var_array is probably the best way of sanitizing the input.
PHP:
list($theName, $theEmail, $theMessage)= filter_var_array($_REQUEST, array(
    theName => FILTER_SANITIZE_SPECIAL_CHARS,
    theEmail => FILTER_SANITIZE_EMAIL,
    theMessage => FILTER_SANITIZE_SPECIAL_CHARS
));

If you were going to pass the data to (e.g.) MySQL, you'd use PDO or (failing that) mysql_real_escape_string
 

kennbona

New Member
Messages
27
Reaction score
0
Points
0
hi, thanks for the reply.. all of you..

at the moment the form is successfully sending the e-mails and the vareables are being read too "thanks ziyadg"... But now there is a new problem... in flash, after clicking send... The message Failed text is appearing.. even though the form is sending the e-mail...

i tried using the origional code but still it doesnt work...
what i dont understand is that the same code is being used but its not working..
this code didn't work..
PHP:
if($sentOk) {
    echo "status=Message Sent!";
} else {
    echo "status=Sending Failed.";
}

and still the origional code "which was working" stopped working.
PHP:
echo "sentOk" . $sentOk;

in Flash, there are two sets of frames labled "success" & "failed"
the script is supposed to send a msg back to flash if the e-mail is sent and the message is supposed to contain either success or failed.. AS then decides which set of frames to play according to the received data from php by matching the names.

________________________________

Thank you also misson,

about that friend, well he said he needs it in flash.. what ever the reason. I personally think he's heard too much pro flash comments and he doesnt want to know about any other alternatives. I think he wants the looks not the works if you know what i mean. I told him that those running older browsers with no flash plugins will have trouble viewing it not to mention that it looks ugly in IE with the enable contents thing.. but still he wants flash.

PHP:
list($theName, $theEmail, $theMessage)= filter_var_array($_REQUEST, array(
    theName => FILTER_SANITIZE_SPECIAL_CHARS,
    theEmail => FILTER_SANITIZE_EMAIL,
    theMessage => FILTER_SANITIZE_SPECIAL_CHARS
));
i used this code just under the opening phptag "<?php" how can i test to see if it's working...? is that the appropriate place to insert it?

Thanks in advance
kenneth
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
this code didn't work..
PHP:
if($sentOk) {
    echo "status=Message Sent!";
} else {
    echo "status=Sending Failed.";
}

and still the origional code "which was working" stopped working.
PHP:
echo "sentOk" . $sentOk;

in Flash, there are two sets of frames labled "success" & "failed"
the script is supposed to send a msg back to flash if the e-mail is sent and the message is supposed to contain either success or failed.. AS then decides which set of frames to play according to the received data from php by matching the names.
Debugging lesson: in a case like this, the PHP script isn't sending a message indicating success, the Flash form isn't processing the received message properly or the flash form isn't displaying the right frame. It's not likely the first case, but you should still test all possibilities in order. Submit a message to the PHP script by URL (which is one reason I use $_REQUEST instead of $_POST) or by HTML form. Make sure you get the output you expect. Then use a debugger to step through the response handler in the Flash form, to make sure it detects a "success" message as a "success" message and see what happens when showing the frame.

Thank you also misson,

about that friend, well he said he needs it in flash.. what ever the reason. I personally think he's heard too much pro flash comments and he doesnt want to know about any other alternatives. I think he wants the looks not the works if you know what i mean. I told him that those running older browsers with no flash plugins will have trouble viewing it not to mention that it looks ugly in IE with the enable contents thing.. but still he wants flash.
Then he's a fool. As the developer, you have a duty to keep your clients from making mistakes, but it only extends so far. If he's insistent, tell him "it's your funeral".

PHP:
list($theName, $theEmail, $theMessage)= filter_var_array($_REQUEST, array(
    theName => FILTER_SANITIZE_SPECIAL_CHARS,
    theEmail => FILTER_SANITIZE_EMAIL,
    theMessage => FILTER_SANITIZE_SPECIAL_CHARS
));
i used this code just under the opening phptag "<?php" how can i test to see if it's working...? is that the appropriate place to insert it?
Answering the two questions in reverse: the best place to filter is when you first get the form variables; second best is just before passing the variables to a subsystem. A proper design might involve both, the first for general clean-up, the second for any cleanup specific to the subsystem. If you're passing the data to N subsystems, you'll sanitize N+1 times. For your script, the start is a good place to do it.

To test filtering, send something malicious. Create an HTML form using a <textarea> for theEmail (so you can easily enter newlines). Try adding headers in theEmail and a script (something simple that just pops up an alert) in theMessage. Rather than waiting for the e-mail to come, you can add code to the PHP script that checks for an input variable named "dbg" and, if true, print out the input variables after they've been filtered.
 

xav0989

Community Public Relation
Community Support
Messages
4,467
Reaction score
95
Points
0
I also like to never use the $_REQUEST variable. Since it's a merge of $_COOKIE, $_GET and $_POST, variables can easily be overwritten. I prefer to use the correct variable from the start.

I your case, that is $_POST.

Also, as a naming convention, don't use <?PHP, but <?php.
 

mattura

Member
Messages
570
Reaction score
2
Points
18
Use $_REQUEST for debugging, then you can test the php side by putting cariables in the url and navigate to it:
PHP:
<?php
$theName = $_REQUEST['theName'];
echo "theName='$theName'";  //or email or whatever
?>

http://www.***.com/send.php?theName=Joe&theMessage=hello etc

Also, try putting &s before any variables you send - this ensures they are not merged with any previous text.
PHP:
echo "My Test";
echo "status=ok";
...is wrong as it passes the following to flash: "My Teststatus=ok", so flash doesn't see 'status' but 'Teststatus'
Whereas this:
PHP:
echo "My Test";
echo "&status=ok";
is fine, as flash sees "My Test&status=ok", and can separate the text as in url variables.

Edit:
if the above & causes your script to work, but no email to be sent, what is probably happening is the "mail" function returns some error (find out what it is!), causing text to be sent to flash in front of the "status", meaning the "status" cannot be read.
 
Last edited:

sonuame

New Member
Messages
2
Reaction score
0
Points
0
Well, using a flash page as a mailer form z realy nt a goot idea...

Y dnt u try cgi, its fast n relaible too
 

damianj

New Member
Messages
1
Reaction score
0
Points
0
I have a flash e-mail form but what I did is to load the variables using a movie clip. Here's the code for when you click the send button.

Code:
on (release) {
    checkForm();
    function validateEmail(address:String) {
        // Check address length
        if (address.length>=7) {
            // Check for an @ sign
            if (address.indexOf("@")>0) {
                // Check for at least 2 characters following the @
                if ((address.indexOf("@")+2)<address.lastIndexOf(".")) {
                    // Check for a domain name of at least 2 characters
                    if (address.lastIndexOf(".")<(address.length-2)) {
                        // If all the above tests pass, the email address is in valid format
                        trace("Email validation passed.");
                        return true;
                    }
                }
            }
        }
        // Called if the email fails     
        trace("The entered email address is invalid.");
        return false;
    }
    function checkForm() {
        var n:String = this.form.name;
        var e:String = this.form.email;
        var m:String = this.form.message;
        if (m != "" && e != "" && validateEmail(e)) {
            trace("Mail function requested.");
            sendEmail();
        } else {
        }
    }
    function sendEmail() {
        this.form.loadVariables("flashemail.php","POST");
        trace("E-mail sent!");
    }
}

then on the actual movie clip itself I have this code

Code:
onClipEvent(data){ 
   this._parent.gotoAndPlay(this._parent._currentframe+1);
}

it's basically telling the movie clip to go to the next frame when the data has been sent. of course you can make it do whatever you want not necessarily go to the next frame.


Here is the code for the php file itself.

Code:
<?php

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$name = trim($name);
$email = trim($email);
$message = StripSlashes($message);
$sendTo = "jimenez.damian@hotmail.com";
$subject = "DamianJimenez.com - Comment/Inquiry";
$headers = "From: " . $name ." <" . $email .">\r\n";
$headers .= "Reply-To: " . $email . "\r\n";
$headers .= "Return-path: " . $email;

mail($sendTo, $subject, $message, $headers);

?>

Also you can get around the "enable content" thing in IE and other browsers that do the same thing by using SWFObject. You can see for yourself on my website http://damianjimenez.com And you can find out about SWF Object here http://blog.deconcept.com/swfobject/#download Also this is version 1.5 of SWF Object although they are on 2.1 now I think its better to use this if youre going to use the macMouseWheel function in your flash site. If you don't know what im talking about or arent going to use it then just get the latest swf object here http://code.google.com/p/swfobject/
 
Last edited:
Top