Changing submit to email based on selection

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • jacobhebert
    Staff Sergeant

    • Jan 2008
    • 44

    Changing submit to email based on selection

    Hello,

    I have created a loan application form for a financial company, and I am trying to figure out how to set it up so that the email address that the form is submitted to, changes based on the location they choose from a drop down menu. Is this possible?

    I have uploaded the basic form to a blank page here in case that helps.

    Also, I was wondering if anyone knows how to make a checkbox a required field? Thanks so much in advance!
    Jacob Hebert
    Lake Conroe Real Estate
  • navaldesign
    General & Forum Moderator

    • Oct 2005
    • 12080

    #2
    Re: Changing submit to email based on selection

    Quite possible. Call your drop down "mailto" and in the standard script, replace this line:

    $mailto = youremail@yourdomain.com;

    with

    $mailto = $_POST['mailto'];


    However, please note that unless you embedd some protection measures, such a form can be easily exploited by spammers to send spam.

    It would be preferable changing the script so that in anycase it will recieve the name (or something similar) of the reciever, and select the email address from a hardcoded list.

    To make your checkbox required:

    There are many ways to make a checkbox required, depends on how you want the error message given.
    Navaldesign
    Logger Lite: Low Cost, Customizable, multifeatured Login script
    Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
    DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
    Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

    Comment

    • jacobhebert
      Staff Sergeant

      • Jan 2008
      • 44

      #3
      Re: Changing submit to email based on selection

      You are awesome, that worked great!

      So if I just set the value of each selection to the corresponding email address, spammer's are able to exploit the form although they can't actually see the email addresses? If so do you know where I could find a tutorial on setting up a hardcoded reference list?

      Thanks again.

      Jacob
      Jacob Hebert
      Lake Conroe Real Estate

      Comment

      • navaldesign
        General & Forum Moderator

        • Oct 2005
        • 12080

        #4
        Re: Changing submit to email based on selection

        Yes, because this means that your script will accept ANY email address that are passed. Of course, security is more than that, however, this is what you need to do:

        1. Name the dropdown "mailto"
        2. Give values like 1,2,3,4 to the corresponding names
        3. Change your script with this:

        <?php
        $reciever = $_POST'mailto'];
        $email = $_POST['email'];
        switch ($reciever) {
        case "1":
        $mailto = "address1@yourdomain.com";
        break;
        case "2":
        $mailto = "address2@yourdomain.com";
        break;
        case "3":
        $mailto = "address2@yourdomain.com";
        break;
        case "4":
        $mailto = "address2@yourdomain.com";
        break;
        default:
        header("Location: errorpage.html"); // This line will send spammers to a errorpage
        exit;

        }

        if ($email == "") {
        $email = $mailto;
        }
        $mailsubj = "Type your mail subject here";
        $mailhead = "From: $email\n";
        reset ($HTTP_POST_VARS);
        $mailbody = "Values submitted from web site form :\n";
        while (list ($key, $val) = each ($HTTP_POST_VARS))
        {
        if ($key!="submit")
        {
        $mailbody .= "$key : $val\n";
        }
        }
        mail($mailto, $mailsubj, $mailbody, $mailhead);
        ?>

        Please note the existance of the error page: it will send to an error page spammers that will try to use your ACTION script to send spam, because the script will only accept the predefined email addresses . However, there are NO OTHER security measures here
        Navaldesign
        Logger Lite: Low Cost, Customizable, multifeatured Login script
        Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
        DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
        Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

        Comment

        • jacobhebert
          Staff Sergeant

          • Jan 2008
          • 44

          #5
          Re: Changing submit to email based on selection

          First, thanks so much for your help with this, it would have taken me so long to research myself.

          I adjusted the action page and changed the values in the combobox and when I submit a form (or just try to load the action page) I get the following message:

          Warning: Cannot modify header information - headers already sent by (output started at /home/username/public_html/application1.php:7) in /home/username/public_html/application1.php on line 136

          I probably left something out, or changed something I shouldn't have! If you need anymore information please feel free to email me at jacob@jacobhebert.com

          Thanks again!
          Jacob Hebert
          Lake Conroe Real Estate

          Comment

          • navaldesign
            General & Forum Moderator

            • Oct 2005
            • 12080

            #6
            Re: Changing submit to email based on selection

            The above code must be pasted in the Start of Page of your page HTMl. Otherwise, if you have some other output to the screen before that, it will give you this error. Delete it from where you have it, and paste it in the Start of page. If there is still a problem, post again.
            Navaldesign
            Logger Lite: Low Cost, Customizable, multifeatured Login script
            Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
            DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
            Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

            Comment

            • jacobhebert
              Staff Sergeant

              • Jan 2008
              • 44

              #7
              Re: Changing submit to email based on selection

              Ok that was one problem, now when I submit, it takes me to the error page instead of the action page and doesn't send the email. I will paste the code thats in my application page to see if you can see what I most assuredly did wrong.

              <?php
              $reciever = $_POST_['mailto'];
              $email = $_POST_['email'];
              switch ($reciever) {
              case "1":
              $mailto = "aaaa@222financialservices.com";
              break;
              case "2":
              $mailto = "bbbb@222financialservices.com";
              break;
              case "3":
              $mailto = "cccc@222financialservices.com";
              break;
              case "4":
              $mailto = "dddd@222financialservices.com";
              break;
              case "5":
              $mailto = "eeee@222financialservices.com";
              break;
              case "6":
              $mailto = "ffff@222inancialservices.com";
              break;
              case "7":
              $mailto = "gggg@222financialservices.com";
              break;
              case "8":
              $mailto = "hhhh@222financialservices.com";
              break;
              case "9":
              $mailto = "iiii@222financialservices.com";
              break;
              case "10":
              $mailto = "jjjj@222financialservices.com";
              break;
              case "11":
              $mailto = "kkkk@222financialservices.com";
              break;
              case "12":
              $mailto = "llll@222financialservices.com";
              break;
              case "13":
              $mailto = "mmmm@222financialservices.com";
              break;
              default:
              header("Location: errorpage.html"); // This line will send spammers to an errorpage
              exit;

              }

              if ($email == "") {
              $email = $mailto;
              }
              $mailsubj = "Credit Application";
              $mailhead = "From: $email\n";
              reset ($HTTP_POST_VARS);
              $mailbody = "The following values were submitted from the TJD website:\n";
              while (list ($key, $val) = each ($HTTP_POST_VARS))
              {
              if ($key!="submit")
              {
              $mailbody .= "$key : $val\n";
              }
              }
              mail($mailto, $mailsubj, $mailbody, $mailhead);
              ?>
              Jacob Hebert
              Lake Conroe Real Estate

              Comment

              • navaldesign
                General & Forum Moderator

                • Oct 2005
                • 12080

                #8
                Re: Changing submit to email based on selection

                Sorry,

                my mistake, should be $_POST['mailto'] and $_POST['email'] no underscore between POST and [
                Navaldesign
                Logger Lite: Low Cost, Customizable, multifeatured Login script
                Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                Comment

                • jacobhebert
                  Staff Sergeant

                  • Jan 2008
                  • 44

                  #9
                  Re: Changing submit to email based on selection

                  Like a charm. Thanks again buddy.
                  Jacob Hebert
                  Lake Conroe Real Estate

                  Comment

                  Working...
                  X