11 Replies Latest reply on Feb 13, 2012 7:19 AM by Zinger@Zohna

    php form not sending any data

    Zinger@Zohna

      Hi,
      My contact form is not giving out any data to my e-mail.
      I'm using two input feilds with instance names as theEmail and theMessage on my action script from which data for the sender's email & the message will be retrieved.

       

      Here is the action action script code i'm using -

       

      snd_btn.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);

       

      function fl_MouseClickHandler(event:MouseEvent):void

      {

                if (theEmail.text == "" || theMessage.text == "")

                {

                          theFeedback.text = "Please fill in all fields."; //if the user misses out a feild, it gives out this message

                }

                else

                {

                          // create a variable container

                          var allVars:URLVariables = new URLVariables();

                          allVars.email = theEmail.text;

                          allVars.message = theMessage.text;


                          //send info to a URL

                          var mailAddress:URLRequest = new URLRequest("mail.php");

                          mailAddress.data = allVars;

                          mailAddress.method = URLRequestMethod.POST;

                          sendToURL(mailAddress);

                          theFeedback.text = "Thank You!";  //if the user fills in all feilds, it gives out this message

                          theEmail.text = "";

                          theMessage.text = "";

                }

      }

       

      and the mail.php script i'm using is this

      .

      <?php

      $to = "mymail@mydomain.com";

      $subject = ($_POST['name']);

      $message = ($_POST['message']);

      $message .= "\n\n---------------------------\n";

      $message .= "E-mail Sent From: " . $_POST['name'] . " <" . $_POST['email']  . ">\n";

      $headers = "From: " . $_POST['name'] . " <" . $_POST['email'] . ">\n";

      if(@mail($to, $subject, $message, $headers))

      {

                echo "answer=ok";

      }

      else

      {

                echo "answer=error";

      }

      ?>

       

      I think the error has to do with my php script...i am really new at this. could anyone please help?

        • 1. Re: php form not sending any data
          kglad Adobe Community Professional & MVP

          you need to send a name variable to that script and use navigateToURL() instead of sendToURL()

          • 2. Re: php form not sending any data
            Zinger@Zohna Level 1

            Ok... like i said, I real new at this, the script is what i learned from a tutorial.

            Could you kindly elaborate on your aspect please? sorry

            • 3. Re: php form not sending any data
              kglad Adobe Community Professional & MVP

               

              snd_btn.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);

               

              function fl_MouseClickHandler(event:MouseEvent):void

              {

                        if (theEmail.text == "" || theMessage.text == "")

                        {

                                  theFeedback.text = "Please fill in all fields."; //if the user misses out a feild, it gives out this message

                        }

                        else

                        {

                                  // create a variable container

                                  var allVars:URLVariables = new URLVariables();

              allVars.name="zinger";

                                  allVars.email = theEmail.text;

                                  allVars.message = theMessage.text;


                                  //send info to a URL

                                  var mailAddress:URLRequest = new URLRequest("mail.php");

                                  mailAddress.data = allVars;

                                  mailAddress.method = URLRequestMethod.POST;

                                  navigateToURL(mailAddress);  // the following doesn't make much sense if you're using navigateToURL().  you should be using a urlloader if you want your swf to persist in the browser.

                                  theFeedback.text = "Thank You!";  //if the user fills in all feilds, it gives out this message

                                  theEmail.text = "";

                                  theMessage.text = "";

                        }

              }

               

              • 4. Re: php form not sending any data
                Cyboide Level 3

                Hi,

                 

                To debug such a problem, you should first trace what you will be sending from Flash; then if the problem seems to be coming from the php script, you can hardcode the received data (example: $_Post['name'] = 'myFakeValue';) at the top of that script and test it directly in the browser. Then you will at least be sure where the problem comes from.

                 

                ____________________

                Design Cyboïde

                • 5. Re: php form not sending any data
                  Zinger@Zohna Level 1

                  can you kindly direct me to some links to such tutorials which offers step by step process for contact forms?

                   

                  it would help me immensly!! thanks in advance

                  • 6. Re: php form not sending any data
                    Cyboide Level 3

                    Here is one of so many:

                    http://www.flepstudio.org/forum/tutorials/3319-creating-email-form-actionscript-3-0-php.ht ml

                    The php script looks pretty straight forward from what I saw.

                    But like I said, you should trace and test.

                    (Otherwise, by the way, I googled "as3 form php", there's quite a lot.)

                     

                    ____________________

                    Design Cyboïde

                    • 7. Re: php form not sending any data
                      Zinger@Zohna Level 1

                      Hi, thanks for the link but cudn't really help out much with that one. but i found another link which was helpful.

                      My default script is in actionscript 3 and this code is in actionscript 1. I got the php script that works with it too.

                       

                      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);

                                };

                      };

                       

                      evrything is working fine except that the problem is on debugging, the line of code with the 'and' syntax is not correctly supported on actionscript 3.
                      it's defining an event where if all the input feilds are filled, then it sends the data to the mailer.php
                      whats the correct way to write that particular line in actionscript 3? pliZ help.

                      • 8. Re: php form not sending any data
                        Cyboide Level 3

                        It should be:

                         

                        if (my_vars.sender != "" && my_vars.subject != "" && my_vars.message != "") {

                         

                         

                        ____________________

                        Design Cyboïde

                        • 9. Re: php form not sending any data
                          Zinger@Zohna Level 1

                          mmm.... before i got only one line of error which said... rightparen expected before and. when i was using the above mentioned code.

                           

                          now after putting the '&&' syntax, the error have increased quite a lot.
                          here is the entire code i'm using on that frame.

                           

                          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);

                            }

                          };

                           

                          is .useCodepage and .onRelease supported in Actionscript 3.
                          sorry, i know this are really dull Q's but i'm really new to actionscript.

                          • 10. Re: php form not sending any data
                            Cyboide Level 3

                            Yes well, that's why I pointed you to an AS3 tutorial.

                            .onRelease is not really the way anymore, amongs other things.

                            You should try a tutorial already in AS3; just take the bits of code you need for sending the data.

                             

                            ____________________

                            Design Cyboïde

                            • 11. Re: php form not sending any data
                              Zinger@Zohna Level 1

                              Yea i gues...!!I
                              But thankz newaz.