2 Replies Latest reply on Feb 1, 2007 8:11 AM by finalcutexpress

    Flash and PHP

    finalcutexpress
      I downloaded a Flash file with accompanying php file from the exchange. The actionscript and php seem pretty straightforward, but I cannot get it to work. It consists of an HTML page that embeds the .swf and the .php file called to action from within the .swf. The .swf is an interface that allows someone to send an email via .php.

      The actionscript in my Flash file is as follows:

      stop();
      System.useCodepage = true;
      send_btn.onRelease = function() {
      my_vars = new LoadVars();
      my_vars.sender = email_box.text;
      my_vars.subject = subject_box.text;
      my_vars.message = message_box.text;
      if (my_vars.sender != "" and my_vars.subject != "" and my_vars.message != "") {
      my_vars.sendAndLoad("mailer.php", my_vars, "POST");
      gotoAndStop(2);
      } else {
      error_clip.gotoAndPlay(2);
      }
      my_vars.onLoad = function() {
      gotoAndStop(3);
      };
      };
      email_box.onSetFocus = subject_box.onSetFocus=message_box.onSetFocus=function () {
      if (error_clip._currentframe != 1) {
      error_clip.gotoAndPlay(6);
      }
      };

      The mailer.php file is:

      <?php

      // read the variables form the string, (this is not needed with some servers).
      $subject = $_REQUEST["subject"];
      $message = $_REQUEST["message"];
      $sender = $_REQUEST["sender"];

      $full_message = $_SERVER['REMOTE_ADDR'] . "\n\n" . $message;
      $message= $full_message;

      /$message = stripslashes($message);
      $subject = stripslashes($subject);
      $sender = stripslashes($sender);

      $subject = "Contact form ". $subject;

      if(isset($message) and isset($subject) and isset($sender)){
      mail("blahblah@blahblah.net", $subject, $message, "From: $sender");
      // the blahblah@ has been replaced with my real email address on the file residing on my server
      // I changed it here for privacy reasons
      }
      ?>

      At present, I have all files residing in the root folder.

      Any suggestions as to why this isn't working -- something on my php.ini file perhaps?

      Thanks in advance for any/all suggestions.
        • 1. Re: Flash and PHP
          Level 7
          Couple things that I notice. First, I never like using only one LoadVars
          object for both sending and receiving, it just never seems to work properly.
          Instead, I do:

          var receiver:LoadVars = new LoadVars();
          var sender:LoadVars = new LoadVars();

          receiver.onLoad = function(success:Boolean){
          trace(success);
          }

          sender.from = email_box.text;
          sender.subject = subject_box.text;

          sender.sendAndLoad("full_url_to_php_script - not just mailer.php",
          receiver);

          Note that you need the full URL to your mailer.php script, and you don't
          need to specify Post, it's the default.

          In your PHP you should change the $_REQUEST's to $_POST's once you're done
          with testing. Otherwise, the parameters can be passed in the URL itself and
          your mailer can be used by anyone.


          --
          Dave -
          Head Developer
          www.blurredistinction.com
          Adobe Community Expert
          http://www.adobe.com/communities/experts/


          • 2. Re: Flash and PHP
            finalcutexpress Level 1
            Hi Dave -

            Thanks very much for the suggestion(s). I'll give it a try.