Menu

Send autoreply based on form selections

Help
SincoMart
2009-05-28
2013-06-03
  • SincoMart

    SincoMart - 2009-05-28

    Hi,

    I created a form and I've got it working perfectly with an autoreply message and everything. the only trouble is that when I try to customize the reply based on the selection made in a specific field I have a problem doing so... I'm not quite sure how to tweak the code to facilitate that function.

    Here's what I have so far...
    <?php

    $where_form_is="http://".$_SERVER['SERVER_NAME'].strrev(strstr(strrev($_SERVER['PHP_SELF']),"/"));

    $to = "email@domain.com";
    $subject = "Subject";
    $message_1 = "
    Username: " . $_POST['field_1'] . "
    Password: " . $_POST['field_2'] . "

    First Name: " . $_POST['field_3'] . "
    Last Name: " . $_POST['field_4'] . "
    D.O.B.: " . $_POST['field_5'] . "
    Email: " . $_POST['field_6'] . "
    Telephone: " . $_POST['field_7'] . "
    Country: " . $_POST['field_8'] . "
    Payment Option: " . $_POST['field_9'] . "
    ";
    $from = $field_3 . $field_4 . "<".$field_6.">";
    $headers = "From: $from";

    $message_2="You did not select an option. Please return to -website- and select an option to receive further instructions.";

    session_start();
    if( ($_SESSION['security_code']==$_POST['security_code']) && (!empty($_POST['security_code'])) ) {
    mail($to,$subject,$message_1,$headers);

    mail("$field_6","Subject",
    "Thank you for ...... . Here is a copy of the information you submitted:

    $message_1

    In order to ...... using the following information:

    $message_2

    We look forward to working with you.
    ,"From: email@domain.com");

    include("confirm.html");
    }
    else {
    echo "Invalid Captcha String.";
    }

    ?>

    That works fine as is but I wanted to edit $message_2 based on the option selected in field_9. Here are two codes I've tried adding:
    1.   if($field_9="Bank Deposit"){
    $message_2="Bank Deposit Instructions";
    } else if($field_9="PayPal"){
    $message_2="PayPal Instructions";
    } else if($field_9="Visa/MasterCard"){
    $message_2="Visa/MasterCard Instructions";
    } else if($field_9=Western Union"){
    $message_2="Western Union Instructions";
    } else {
    $message_2="You did not select an option. Please return to -website- and select an option to receive further instructions.";
    2.   if($Bank Deposit_field){
    $message_2="Bank Deposit Instructions";
    } else if($PayPal_field){
    $message_2="PayPal Instructions";
    } else if($Visa/MasterCard_field){
    $message_2="Visa/MasterCard Instructions";
    } else if($Western Union_field){
    $message_2="Western Union Instructions";
    } else {
    $message_2="You did not select an option. Please return to -website- and select an option to receive further instructions.";

    None of these have actually worked... what am I doing wrong?... what should I do to fix it?

     
    • TNTEverett

      TNTEverett - 2009-05-29

      Try assigning a variable first before trying to use it.

      $field_9 has no value unless assigned like this:
      $field_9=$_POST['field_9'];

      Then you test
      if($field_9="Bank Deposit")
      must match exactly unless you use something like the preg_match() function.

      http://us2.php.net/preg_match

       
    • SincoMart

      SincoMart - 2009-05-29

      I don't understand the preg_match bit but I tried what you suggested and it didn't work
      I also went ahead and tried:
      if($_POST['field_9'] = "Bank Deposit"){ 
      $message_2="Bank Deposit Instructions";
      but it didn't work either.
      Any other suggestions?

       
      • TNTEverett

        TNTEverett - 2009-05-29

        As a test put this right before your first test:

        echo "<li> ".$_POST['field_9']."<br />";
        exit;
        if($_POST['field_9'] = "Bank Deposit"){ 

         
    • SincoMart

      SincoMart - 2009-05-29

      Still doesn't work :(

       
      • TNTEverett

        TNTEverett - 2009-05-29

        What do you mean it doesn't work?
        My suggestion would have resulted only in a variable printed to the screen.  Of course it would not work, "exit" neans QUIT.

        If the form did not print this variable and QUIT then you either did something wrong or the file you midified is not the file on your site. 

         
    • SincoMart

      SincoMart - 2009-05-29

      What else can I try?

       
    • SincoMart

      SincoMart - 2009-05-29

      It didn't print anything and all I did was copy and paste exactly what you gave me in the order you gave me so I don't see how I could have done anything wrong... the file is also correct so what now?

       
    • SincoMart

      SincoMart - 2009-05-29

      Never mind... I just realized that the last brackets weren't closed properly, that's why I had a problem [duh!] lol
      Thanks for your help :)

       
    • SincoMart

      SincoMart - 2009-05-29

      OK, new problem... I got the form to process with the new code now but the values keep getting mixed up and I don't know why.
      This is what I have:

      if($_POST['field_6']="Bank Deposit"){$message_2="Bank Deposit Instructions";}
      else if($_POST['field_6']="PayPal"){$message_2="PayPal Instructions";}
      else if($_POST['field_6']="Visa/MasterCard"){$message_2="Visa/MasterCard Instructions";}
      else if($_POST['field_6']="Western Union"){$message_2="Western Union Instructions";}
      else {$message_2="Please revisit http://dataentry.sincomart.com/registration.html and select a Payment Option to receive further instructions";}

      but it's not obeying the commands I've set out... can you help?

       
    • SincoMart

      SincoMart - 2009-05-29

      for example I select "Western Union" but the message that gets emailed is "Bank Deposit Instructions"
      How can I fix this?

       
      • TNTEverett

        TNTEverett - 2009-05-30

        Your code only knows how to do what you tell it to do.  So your code is wrong.  In order to find out what is wrong you need to find out what it is that you have told it to do.  The last suggestion I made was to print the variable value you are using to produce a different message.  If the value is wrong, then the message will be wrong. 

         
        • SincoMart

          SincoMart - 2009-05-30

          I kinda figured out that my code is wrong, hence why I quoted in the message so you could help me correct it... that is what I'm asking you to do... can you?

           
          • TNTEverett

            TNTEverett - 2009-05-30

            I can help but your going to have to send me everything you have so I can simulate it on my computer. 
            Zip up your entire form and send it to me in an email. 

             
    • SincoMart

      SincoMart - 2009-05-30

      OK... I did the print test thing again using a different computer this time and it seems to be working fine so I don't think the problem is the code.
      My concern though is whether or not my users may encounter the problem that I had when I was using that other machine... do you think that is likely?

       
    • SincoMart

      SincoMart - 2009-05-30

      I just realized that even though the print test shows the correct message, when I retest the actual form I have the same problem... I'm not sure how to proceed.

       

Log in to post a comment.