15 Replies Latest reply on Feb 18, 2010 2:51 PM by kglad

    Send mail with PHP, missing input text?

    ommvc61 Level 1

      Please help, this can't be difficult to solve. I've created a simple Flash contact form that uses PHP. It functions, but the results in the delivered email do not include the text from the inputs fields in Flash. Also, it does not return a "From" or "Reply-to" value. (This is from a simple tutorial followed exactly, except with 3 added fields. It uses the "LoadVars" method in Actionscript.)

       

      Here is the Actionscript code:

       

      stop();

       

      var senderLoad:LoadVars = new LoadVars();

      var receiveLoad:LoadVars = new LoadVars();

       

           sender.onRelease = function() {

           senderLoad.theName = theName.text;

           senderLoad.theEmail = theEmail.text;

           senderLoad.thePhone = thePhone.text;

           senderLoad.theBuilddate = theBuilddate.text;

           senderLoad.theLot = theLot.text;

           senderLoad.theMessage = theMessage.text;

           senderLoad.sendAndLoad("http://betaclient2.ommvc.com/send.php",receiveLoad);

      }

       

      receiveLoad.onLoad = function() {

           if(this.sentOk) {

           _root.gotoAndStop("success");

           }

           else {

           _root.gotoAndStop("failed");

           }

      }

       

      Here is the PHP page code:

       

      <?PHP

       

      $to = "dan.ommvc@comcast.net";

      $subject = "Custom Home Inquiry";

      $message = "Name: " . $theName;

      $message .= "\nEmail: " . $theEmail;

      $message .= "\nPhone: " . $thePhone;

      $message .= "\nBuilddate: " . $theBuilddate;

      $message .= "\nLot: " . $theLot;

      $message .= "\n\nMessage: " . $theMessage;

      $headers = "From: $theEmail";

      $headers .= "\nReply-To: $theEmail";

       

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

       

      echo "sentOk=" . $sentOk;

       

      ?>

       

      (Using Dreamweaver CS4, Flash CS4)

        • 1. Re: Send mail with PHP, missing input text?
          kglad Adobe Community Professional & MVP

          use:

           


           

           

          stop();

           

          var senderLoad:LoadVars = new LoadVars();

          var receiveLoad:LoadVars = new LoadVars();

           

          receiveLoad.onLoad = function() {

               if(this.sentOk) {

               _root.gotoAndStop("success");

               }

               else {

               _root.gotoAndStop("failed");

               }

          }

           

               sender.onRelease = function() {

               senderLoad.theName = theName.text;

               senderLoad.theEmail = theEmail.text;

               senderLoad.thePhone = thePhone.text;

               senderLoad.theBuilddate = theBuilddate.text;

               senderLoad.theLot = theLot.text;

               senderLoad.theMessage = theMessage.text;

               senderLoad.sendAndLoad("http://betaclient2.ommvc.com/send.php",receiveLoad,"POST");

          }

           


           

          Here is the PHP page code:

           

           

          <?PHP

           

          $to = "dan.ommvc@comcast.net";

          $subject = "Custom Home Inquiry";

          $message = "Name: " . $_POST["theName"];

          $message .= "\nEmail: " . $_POST{"theEmail"];  // etc

          $message .= "\nPhone: " . $thePhone;

          $message .= "\nBuilddate: " . $theBuilddate;

          $message .= "\nLot: " . $theLot;

          $message .= "\n\nMessage: " . $theMessage;

          $headers = "From: $theEmail";

          $headers .= "\nReply-To: $theEmail";

           

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

           

          echo "sentOk=" . $sentOk;

           

          ?>

           

           

          • 2. Re: Send mail with PHP, missing input text?
            ommvc61 Level 1

            This might be it, as I've been getting "POST" feedback.

             

            Question on your "PHP" code suggestion:  Are you using "[  ]" or 

            "{ }" ?  It looks like you meant the former, but one is a "{". Please 

            advise...

             

            Thanks

            • 3. Re: Send mail with PHP, missing input text?
              ommvc61 Level 1

              Also, in the PHP code, do I have to include your suggestion in all the 

              fields, or just the ones you specified?  $_POST["theName"];

              • 4. Re: Send mail with PHP, missing input text?
                ommvc61 Level 1

                You've got it!  This fix returns info - thanks much!

                One thing more, The "From" and Reply-To, are still not showing up in 

                the top header of the email. Content looks like this:

                • 5. Re: Send mail with PHP, missing input text?
                  kglad Adobe Community Professional & MVP

                  you're welcome.  please mark this thread as answered, if you can.

                   

                  p.s.  you need to use \r\n or something similar before or after your from and reply-to statements:

                  • 6. Re: Send mail with PHP, missing input text?
                    ommvc61 Level 1

                    I'll check it out. Also, will mark answered.

                     

                    Again, thanks...

                    • 7. Re: Send mail with PHP, missing input text?
                      ommvc61 Level 1

                      Just thought I'd ask, in case your willing to help a bit more, what 

                      would it take to make some of the fields "required"? To put a simple 

                      checker in the code somewhere to make sure all required fields are 

                      filled out before executing the send.

                       

                      I could set up another frame label with a simple message, but wouldn't 

                      know where to starts on the actionscript. If there's a tutorial or 

                      other site you can steer me to, that's fine.

                       

                      Thanks in advance, otherwise the form is functioning perfect.

                       

                      D.

                      • 8. Re: Send mail with PHP, missing input text?
                        kglad Adobe Community Professional & MVP

                        here's sample code:

                         

                        sendBtn.onRelease = function(){
                            if(validEmailF(emailTF.text)){
                                if(nameTF.text.length>2){
                                    if(messageTF.text.length>8){
                                        sendLV.email = emailTF.text;
                                        sendLV.name = nameTF.text;
                                        sendLV.message = messageTF.text;
                                        sendLV.sendAndLoad("php/email.php",receiveLV,"POST");
                                    } else {
                                        ttF("Invalid message",messageTF._y);
                                    }
                                } else {
                                    ttF("Invalid name",nameTF._y);
                                }
                               
                            } else {
                                ttF("Invalid email address",emailTF._y);
                            }
                        }

                         

                        function ttF(s:String,y:Number){
                            var mc:MovieClip = tl.attachMovie("ttID","ttMC_"+dep,dep++);  // create a movieclip with a textfield, tf
                            mc._x = nameTF._x+nameTF._width;
                            mc._y = y;
                            mc.tf.text = s;
                            setTimeout(removeF,3000,mc);
                        }
                        function removeF(mc:MovieClip){
                            mc.removeMovieClip();
                        }

                         

                         


                        function validEmailF(email:String):Boolean {
                            var at:String = "@";
                            var dot:String = ".";
                            var lat:Number = email.indexOf(at);
                            var lemail:Number = email.length;
                            var ldot:Number = email.indexOf(dot);
                            if (email.indexOf(at) == -1) {
                                return false;
                            }
                            if (email.indexOf(at) == -1 || email.indexOf(at) == 0 || email.indexOf(at) == lemail) {
                                return false;
                            }
                            if (email.indexOf(dot) == -1 || email.indexOf(dot) == 0 || email.indexOf(dot) == lemail) {
                                return false;
                            }
                            if (email.indexOf(at, (lat+1)) != -1) {
                                return false;
                            }
                            if (email.substring(lat-1, lat) == dot || email.substring(lat+1, lat+2) == dot) {
                                return false;
                            }
                            if (email.indexOf(dot, (lat+2)) == -1) {
                                return false;
                            }
                            if (email.indexOf(" ") != -1) {
                                return false;
                            }
                            return true;
                        }

                        • 9. Re: Send mail with PHP, missing input text?
                          ommvc61 Level 1

                          Thanks, I'll see what I can do...

                          D

                          • 10. Re: Send mail with PHP, missing input text?
                            ommvc61 Level 1

                            2 questions:

                             

                            1.  Is this Two separate solutions, or are both parts needed?

                             

                            2.  Would this follow the current actionscript that I have, or on its 

                            own "actions" layer?

                             

                            Thx. D.

                            • 11. Re: Send mail with PHP, missing input text?
                              kglad Adobe Community Professional & MVP

                              that's sample code to solve one problem:  make sure the email textfield (emailTF) has a legit email address and make sure the name textfield (nameTF) has, at least, a few characters and make sure the message textfield (messageTF) has, at least, a few characters.

                              • 12. Re: Send mail with PHP, missing input text?
                                ommvc61 Level 1

                                Would those be the "instance names" that I used?

                                • 13. Re: Send mail with PHP, missing input text?
                                  kglad Adobe Community Professional & MVP

                                  either that or change the code to use your instance names.

                                  • 14. Re: Send mail with PHP, missing input text?
                                    TheBrody

                                    I have a question, how do you make it actually send the mail to the person?

                                    • 15. Re: Send mail with PHP, missing input text?
                                      kglad Adobe Community Professional & MVP

                                      you send your data to a server-side script that adds those data to an email and sends it.  the code i showed does that for a php script.