Welcome, Guest. Please login or register.
Did you miss your activation email?
05/21/12, 04:59
Home Help Search Login Register
News: Parsley Flex framework review featuring quiz application, in our Flex frameworks series
Flex SDK 4.5 mobile roadmap: begin with your mobile development
Swiz Flex framework review featuring quiz application
New homepage we release our new Homepage, take a look ...

+  Flash-db
|-+  General
| |-+  Flash and AS 3 (Moderators: papachan, kofi addaquay)
| | |-+  using PHP to send email with contents from flash 9
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] 2 Print
Author Topic: using PHP to send email with contents from flash 9  (Read 4334 times)
aohk666
Server what's that
*
Posts: 13


View Profile Email
« on: 08/16/07, 16:42 »

hey everybody. i've been reading this forum and several others for a few days now and i am still coming up short, though i feel that i am very close to solving this problem. what i need is to be able to capture data from an input box and send it in an email. i understand that there is a section all about this on this message board, but everything is for AS2 or earlier. i've read the "saving dynamic data from Flash using AS 3" but it is still not working. any help would be awesome. i am going to post what i have so far below. thanks ahead of time.

Code:
function sendData(evt:MouseEvent):void{
    var myData:URLRequest = new URLRequest("mailform.php")
    myData.method = URLRequestMethod.POST;
    var variables:URLVariables = new URLVariables();
    variables.Title = emailInput_txt.text;
    myData.data = variables;
    var loader:URLLoader = new URLLoader();
    loader.load(myData);
}

emailBtn.addEventListener(MouseEvent.CLICK, sendData);

Code:
<?php
//Capture data from $_POST array
$title $_POST['Title'];
//Make one big string in a format Flash understand
$toSave ="Title=$title";
//Open a file in write mode
$fp fopen("email.txt""w");
if(
fwrite($fp$toSave)) echo "writing=Ok&";
else echo 
"writing=Error&"
fclose($fp);
?>

also, i was just trying to send the info to a local empty text file, just to see if it would work that way. still nothing, but what i really need is to send that info in an email.

thanks.
Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14600


View Profile
« Reply #1 on: 08/17/07, 01:14 »

The code looks good. Try with AS2 and the same PHP script first (you can copy the code from http://www.flash-db.com/Tutorials/saving/savingData.php?page=2 )

Jorge
Logged

Ronald Wernecke
Administrator
Systems Administrator
*****
Posts: 6175


View Profile WWW Email
« Reply #2 on: 08/17/07, 02:20 »

I think the problem is not the code, but maybe the rights and ability of the server.

Did you send mails via script on this server before?
Does the testfile, you can find in our mail tutorial, send mail?
Can you write other information into the file?
Do you receive the variables into your script?
What happens, if you call your script in the browser?
Logged

happy flashing
Cool
Ronald
aohk666
Server what's that
*
Posts: 13


View Profile Email
« Reply #3 on: 08/17/07, 10:05 »

well. i know that the server has the capability to run PHP and we have successfully with AS2 before. But i did try the tutorial and that did not work either. other than tracing...how would i know if i am receiving variables into the script?

thanks for the speedy responses.
Logged
BurtonRider1983
Global Moderator
Systems Administrator
*****
Posts: 864

Rider-4-Life

BurtonRider1983
View Profile WWW
« Reply #4 on: 08/17/07, 10:21 »

Service Capture is a great program for debugging the communication between flash and server side technologies (but not at all limited to).
Some of my projects couldn't have been completed without it or an equivalent tool.
You can view all the information sent to and from php.  I would just put some return statements in your code to see if they return the values through service capture and move your return statements further along in your code to see where the issues are occuring.

I don't think it is an error in your php script, I just think that you are missing something that will allow it to run with the settings you have on your server.
Try this line of code at the top of your php script....
Code:
if (isset ($HTTP_POST_VARS)){
    $_POST = &$HTTP_POST_VARS;
}
...that should fix it.
« Last Edit: 08/17/07, 10:23 by BurtonRider1983 » Logged
aohk666
Server what's that
*
Posts: 13


View Profile Email
« Reply #5 on: 08/17/07, 10:24 »

also....i just did the AS2 tutorial... and it worked great. so......maybe there is something wrong with the code?
Logged
aohk666
Server what's that
*
Posts: 13


View Profile Email
« Reply #6 on: 08/17/07, 10:44 »

i just tried again with the piece of code you provided. still nothing. im going to try that service capture program. but will be checking in to see if you have any other advice. im posting the code....does this look okay?

Code:
<?php
if (isset ($HTTP_POST_VARS)){
    
$_POST = &$HTTP_POST_VARS;
}
//Capture data from $_POST array
$title $_POST['Title'];
//Make one big string in a format Flash understand
$toSave ="Title=$title";
//Open a file in write mode
$fp fopen("email.txt""w");
if(
fwrite($fp$toSave)) echo "writing=Ok&";
else echo 
"writing=Error&"
fclose($fp);
?>
Logged
BurtonRider1983
Global Moderator
Systems Administrator
*****
Posts: 864

Rider-4-Life

BurtonRider1983
View Profile WWW
« Reply #7 on: 08/17/07, 10:46 »

one more thing.... Try a query string from flash instead...

AS3.0
Code:
protected function sendEmail(_email, _name, _message):void {         
    var url:String = "sendLink.php?email=" + _email + "&name=" + _name + "&message=" + _message;
    var request:URLRequest = new URLRequest(url);
    sendToURL(request);
}

You can use this and change all the variables in php to GET.
Logged
aohk666
Server what's that
*
Posts: 13


View Profile Email
« Reply #8 on: 08/17/07, 11:38 »

use that code instead of all of the other AS3 code? or do i replace part of it with it?
Logged
BurtonRider1983
Global Moderator
Systems Administrator
*****
Posts: 864

Rider-4-Life

BurtonRider1983
View Profile WWW
« Reply #9 on: 08/17/07, 12:06 »

For your code....
Code:
function sendData(evt:MouseEvent):void {         
    var url:String = "mailform.php?Title=" + emailInput_txt.text ;
    var request:URLRequest = new URLRequest(url);
    sendToURL(request);
}

emailBtn.addEventListener(MouseEvent.CLICK, sendData);
...should work.
Logged
Ronald Wernecke
Administrator
Systems Administrator
*****
Posts: 6175


View Profile WWW Email
« Reply #10 on: 08/17/07, 12:20 »

If you run the same php script you are running for the as 2 sample, you are save (at the php side).
Use Charles for debugging - then you know what is going on at the line.

BTW - if you have a Testversion of Flash CS3, and the testperiode expired, you still can play around, but it will not communicate anymore Wink
Logged

happy flashing
Cool
Ronald
aohk666
Server what's that
*
Posts: 13


View Profile Email
« Reply #11 on: 08/17/07, 12:26 »

yet another failure. there is no error in the AS3 code though, and it runs fine. i really appreciate your help by the way....any other suggestions?
Logged
BurtonRider1983
Global Moderator
Systems Administrator
*****
Posts: 864

Rider-4-Life

BurtonRider1983
View Profile WWW
« Reply #12 on: 08/17/07, 13:15 »

Did you change your php to match the changes in the AS?

PHP code change...
Code:
if (isset ($HTTP_GET_VARS)){
    $_POST = &$HTTP_GET_VARS;
}

You can use that or go through and change all of your $_POST references to $_GET and use proper naming.


Ronald...Never tried Charles...just looked it up and I am downloading it now.  And I didn't know about the way they implemented the trial/test versions of the newest release.  Thanks.
« Last Edit: 08/17/07, 13:19 by BurtonRider1983 » Logged
aohk666
Server what's that
*
Posts: 13


View Profile Email
« Reply #13 on: 08/17/07, 16:05 »

im pretty sure this is on the PHP end, because when i run trace on the request it shows this: [object URLRequest]. so its sending the request it seems. im going to post all my codes again just to be sure, but i have tried the GET and POST each way.
Logged
Ronald Wernecke
Administrator
Systems Administrator
*****
Posts: 6175


View Profile WWW Email
« Reply #14 on: 08/18/07, 02:45 »

Suggestion:
1. make the php code run with Flash 8 and dont touch it
2. make the AS3 version as close as possible identical to the Flash 8 version.
3. use Charles for debugging

You can enhace it later, when the basic communication is running Wink
Logged

happy flashing
Cool
Ronald
Pages: [1] 2 Print 
« previous next »
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
anything