Skip to main content
May 26, 2009
Answered

Loading php output into flash to determine message

  • May 26, 2009
  • 1 reply
  • 1191 views

Hi there,

I am using the following tutorial to create a php message page, however, even in their example, I cannot get the php echo function to send the output to the dynamic text fields: http://www.sephiroth.it/tutorials/flashPHP/email/index.php.

Here is the button code to send the php variables and attempt to capture the php echo of either "sent" or "error"

on (release) {
    //    Now import the variables we
    //    need to send in this movie clip
    sender_mail = _root.Semail.text
    sender_name = _root.Sname.text
    sender_subject = _root.Ssubject.text
    sender_message = _root.Smessage.text
    //    all the vars we just imported
    //    will be sent via POST method now
    loadVariables("sendmail.php",this,"POST");
    //    and when receives the answer from
    //    the server...
    this.onData = function()
    {
        //    ok, next frame
        _root.nextFrame();
        if(this.output=='sent')
        {
            // in case of success
            _root.errTitle = 'Thank You.';
            _root.errType = "Your message has been succesfully sent.";
        } else {
            //    else
            _root.errTitle = "Error!";
            _root.errType = "Attention, an error occurred. Please try again later.";
        }
    }
}

Here is the php which should echo the "sent" or "error"

<?
if(!empty($HTTP_POST_VARS['sender_mail']) || !empty($HTTP_POST_VARS['sender_message']) || !empty($HTTP_POST_VARS['sender_subject']) || !empty($HTTP_POST_VARS['sender_name']))
{
     $to = "email@website.com";
     $subject = stripslashes($HTTP_POST_VARS['sender_subject']);
     $body = stripslashes($HTTP_POST_VARS['sender_message']);
     $body .= "\n\n---------------------------\n";
     $body .= "Mail sent by: " . $HTTP_POST_VARS['sender_name'] . " <" . $HTTP_POST_VARS['sender_mail']  . ">\n";
     $header = "From: " . $HTTP_POST_VARS['sender_name'] . " <" . $HTTP_POST_VARS['sender_mail'] . ">\n";
     $header .= "Reply-To: " . $HTTP_POST_VARS['sender_name'] . " <" . $HTTP_POST_VARS['sender_mail'] . ">\n";
     $header .= "X-Mailer: PHP/" . phpversion() . "\n";
     $header .= "X-Priority: 1";
     if(@mail($to, $subject, $body, $header))
     {
          echo "output=sent";
     } else {
          echo "output=error";
     }
} else {
     echo "output=error";
}
?>

The email does send fine, but it does not show the message which lets the user know the status of the message.  Any ideas?  There is a link to download the .zip file of the tutorial - I have attached it here.
This topic has been closed for replies.
Correct answer kglad

Well, they both exist in both frames of the root, where the presentation of the results occur, but the code is placed within the movieclip, sendMC, ON the instance of sendButton (which is why I am using the on (release) function).  sendMC appears only on the first frame of the root where all the input fields are located.


place both those textfields in their own layer in _root's frame 1.  add a frame (but NOT a keyframe) to frame 2 of the textfields' layer.  retest.

1 reply

kglad
Community Expert
Community Expert
May 26, 2009

does the next frame play?  if so, nextFrame() should execute after you populate your variables.

May 27, 2009

So, what I have done is added the nextFrame to the if statement checking for the php echo:

if(this.output=='sent')
        {
            // in case of success
            _root.errTitle.text = 'Wahoo!.';
            _root.errType.text = "It is sent.";
            _root.nextFrame();
        } else {
            //    else
            _root.errTitle.text = "Uh oh!";
            _root.errType.text = "It didn't go anywhere. Please try again later.";
            _root.nextFrame();
        }

This didn't seem to work either.  I am receiving e-mails fine, but no text is showing up.

In the above example I also added the .text to the two text fields since that was not in the tutorial example I was using.

I even added instances of the two text fields to the first frame to ensure that they are visible across the whole movie.

Any ideas?

kglad
Community Expert
Community Expert
May 27, 2009

again, does the next frame play?