14 Replies Latest reply on Dec 17, 2009 6:35 AM by robdillon

    PHP EMAIL FORM

    spirito78

      Hello,

      I'm having trouble with some code. I would like to add some content to my email form.

      address,city and state. So I did that and I added it where I thought the code went and tested it nothing

      came back with what I added. I know I'm missing something and I feel I'm getting close but no cigar.

      Could somebody help me out on this.

       

      Thanks,

      Tom

        • 1. Re: PHP EMAIL FORM
          robdillon Most Valuable Participant

          These lines in your php file:

          $sender_name = $_POST['name'];
          $sender_name = $_POST['address'];
          $sender_name = $_POST['city'];
          $sender_name = $_POST['state'];

           

          are all creating a variable with the same name and setting its value to different content. You need to change the names of the variables, something like this:

          $sender_name = $_POST['name'];
          $sender_address = $_POST['address'];
          $sender_city = $_POST['city'];
          $sender_state = $_POST['state'];

           

          Then, in the section that starts with "$email_body" you need to add in these variables so that they will be written to the email that this php file creates. Something like this might work:

          $email_body = "    Name: $sender_name \n $sender_customer_type \n Department:  $sender_subject \n Phone:    $sender_phone \n Email: $sender_email \n Address:   $sender_address \n City:   $sender_city \n State: $sender_state \n   Prefered Contact: $sender_preferred_contact \n     Message: $sender_message \n  Add to mailing list? $e_letter \n IP: $client_ip \n Department:

          • 2. Re: PHP EMAIL FORM
            spirito78 Level 1

            Rob,

            I understand it now. I have one other question. On my second combo box

            on my form. When I test the form everything works except the second

            combo box. Please see below.

             

            Thanks,

            Tom

             

            Name: tom

              address: test

              city: test

              state: test

             

              Department:  test

              Phone: test

              Email: tspirito@cox.net

              Preferred Contact:

              Message: test

               Add to mailing list? Yes

              IP: 70.181.51.122

              Department:    ROB this is what I mean.

            • 3. Re: PHP EMAIL FORM
              robdillon Most Valuable Participant

              In the Actionscript on your send frame, comment out the loadVariables... line and add this below that:

               

              for(i in this) {
              trace(this[i] + " " + this[i].value);
              }

               

              Test your movie and enter or select all of the data entries and hit send. You will get a listing of each object on the stage and its value. Some of the items in the list are meaningless. The form items will be obvious. You will need to add each of the items that don't show up in your php to your php file as a variable and again as a value to be written to the email.

              • 4. Re: PHP EMAIL FORM
                spirito78 Level 1

                Rob,

                No go it didn't work. Nothing came up on the second combo box ( drop

                down choices).

                It still reads Department: empty space.

                Getting there I can feel it.

                • 5. Re: PHP EMAIL FORM
                  spirito78 Level 1

                  Rob,

                  No go it didn't work. Nothing came up on the second combo box ( drop

                  down choices).

                  It still reads Department: empty space.

                  Getting there I can feel it.

                  • 6. Re: PHP EMAIL FORM
                    robdillon Most Valuable Participant

                    Show us your files as they are now.

                    • 7. Re: PHP EMAIL FORM
                      spirito78 Level 1

                      Ok here' re my files.

                       

                      Thanks

                      • 8. Re: PHP EMAIL FORM
                        robdillon Most Valuable Participant

                        In your Flash movie, you have one improper instance name in the form. Your second combobox is named, "combo box 2". Instance names need to be one word, so in keeping with your naming convention, rename this instance to: "combo_box_2". With this change, your instance names look like this:

                        sender_name
                        sender_email
                        sender_phone
                        yesCustomer
                        noCustomer
                        emailMethod
                        phoneMethod
                        Combo_box
                        combo_box_2
                        sender_message
                        e_letter

                         

                        In your php file, in the first section where you are defining variables to hold the information that is being sent from the Flash movie, you need to use the same names for the values as you used in the Flash movie as the instance names. The section currently looks like this:

                         

                         

                        So this section should look something like this:

                        $COMBO_PHP_VARIABLE = $_POST['ComboBox_text2'];
                        $sender_name = $_POST['name'];
                        $sender_address = $_POST['address'];
                        $sender_city = $_POST['city'];
                        $sender_state = $_POST['state'];
                        $sender_email = $_POST['email'];
                        $sender_subject = $_POST['subject'];
                        $sender_message = $_POST['message'];
                        $sender_phone = $_POST['phone'];
                        $sender_customer_type = $_POST['customertype'];
                        $sender_preferred_contact = $_POST['preferredcontact'];
                        $e_letter = $_POST['eLetterCheckbox'];

                         

                        You need to change some of these items so that they match the information that you are sending. Some need to be deleted. Maybe something like this:

                         

                        $sender_name = $_POST['sender_name'];
                        $sender_email = $_POST['sender_email'];
                        $sender_phone = $_POST['sender_phone'];
                        $sender_customer_yes = $_POST['yesCustomer'];
                        $sender_customer_no = $_POST['noCustomer'];
                        $sender_preferred_email = $_POST['emailMethod'];
                        $sender_preferred_phone = $_POST['phoneMethod'];

                        $service_choice = $_POST['Combo_box'];

                        $find_us = $_POST['combo_box_2'];
                        $sender_message = $_POST['sender_message'];
                        $e_letter = $_POST['eLetter'];

                         

                        The following is new code that will parse out the user's selection for customer type and contact method:

                        $sender_customer_type = "new";

                        if($sender_customer_yes)

                             {

                             $sender_customer_type = "existing";

                        }

                         

                        $sender_contact = "email";

                        if($sender_preferred_phone)

                             {

                             $sender_contact = "phone";

                        }

                         

                        This second listing is organized in the same order as your Flash form. Once you have this information in your php, then you need to organize it so that it can be sent out as an email. This is the section that starts: "$email_body...". You might change that to look something like this:

                         

                        $email_body = "    Name: $sender_name \n Customer type: $sender_customer_type \n  Phone:    $sender_phone \n Email: $sender_email \n Prefered Contact: $sender_contact \n Message: $sender_message \n  Add to mailing list? $e_letter \n Service interest: $service_choice \n Heard about us: $find_us;

                         

                        This will organize the return email to follow the variable names that are used in the php.  I think the rest of the php will work correctly. I haven't tested this.

                        • 9. Re: PHP EMAIL FORM
                          spirito78 Level 1

                          Rob,

                          I didn't know that thanks. So I wasn't off by much?

                          I understand everything you told me except this:

                           

                           

                          The following is new code that will parse out the user's selection for

                          customer type and contact method:

                          $sender_customer_type = "new";

                          if($sender_customer_yes)

                                {

                                $sender_customer_type = "existing";

                          }

                           

                          $sender_contact = "email";

                          if($sender_preferred_phone)

                                {

                                $sender_contact = "phone";

                          }

                           

                          Does this go into the (send) action script in the fla.

                          • 10. Re: PHP EMAIL FORM
                            robdillon Most Valuable Participant

                            No. That's part of the php. Put that just below the section that sets up all of the other variables.

                            • 11. Re: PHP EMAIL FORM
                              spirito78 Level 1

                              Ok got it.

                              • 12. Re: PHP EMAIL FORM
                                spirito78 Level 1

                                Rob,

                                I just tested it out and it works!  Thanks so much. I would like to

                                learn more about scripting.

                                What do you recommend.

                                 

                                Thanks,

                                Tom

                                • 13. Re: PHP EMAIL FORM
                                  robdillon Most Valuable Participant

                                  O'Reilly has a number of very good books on Actionscript, Perl, PHP, Javascript, etc. For Actionscript there is "Essential Actionscript 3.0" and "Actionscript 3.0 Cookbook".  I like the cookbook books as they have common scenarios and their solutions outlined in detail.

                                  • 14. Re: PHP EMAIL FORM
                                    spirito78 Level 1

                                    Rob,

                                    Thank you for your time and knowledge.

                                     

                                    Tom