One contact form with multiple e-mail options to submit to

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • gillenium
    Sergeant

    • Dec 2008
    • 27

    One contact form with multiple e-mail options to submit to

    Is it possible to have one contact form used to submit information with and select a specific individual to have that information e-mailed directly to?

    Here's the scenario: I would like to have one contact page with one form to submit. However, I have five different people in the office that my website visitors may want to submit their info or questions to. Is there a way for my visitor to select one of the five names, enter in their information, hit submit and have that info e-mailed directly to that individual?

    The way I know how to set up the contact form is to enter the e-mail address to submit to in the Beginning of Body tab of the html properties box on the php page that appears once the info is submitted from the contact form page. I'm assuming you can enter multiple e-mail address separated by commas, but then that contact info would submit to all of the e-mail addresses, rather than just the intended one. Correct?

    So, how can I set it up to send to just one address from multiple selections?

    Thanks in advance for your help and insight!
    Scott

    www.helpingusellu.com
  • navaldesign
    General & Forum Moderator

    • Oct 2005
    • 12080

    #2
    Re: One contact form with multiple e-mail options to submit to

    Quite possible but you will have to use another form processor and not the built in one.

    Here is the process:

    1. Create the form page. Do NOT check the "Use built in form processor" checkbox. Set the action to "confirm.php" where "confirm.php" will be your "thank you" page. Set the encoding type to "multipart / Form data"
    Add a combobox, with the possible choices of departments (persons). The combobox MUST be named "department".
    You can use Radio buttons if you prefer, as long as their Group Name is "department"

    2. Create a thankyou page, named "confirm". Set its extension to be .php
    Add the following code in the page HTML, Start of page:

    Code:
     
    <?php
     
    $subject = 'New Submission from our Multiple Department Website form';
    $message = 'Values submitted from web site form to department: '.$_POST['department'];
    $error_url = 'errorpage.php';
     
    $address[Sales] = "[EMAIL="sales@yourdomain.com"]sales@yourdomain.com[/EMAIL]";
    $address[Warranty] = "[EMAIL="warranty@yourdomain.com"]warranty@yourdomain.com[/EMAIL]";
    $address[Manufacturing] = "[EMAIL="manufacturing@yourdomain.com"]manufacturing@yourdomain.com[/EMAIL]";
    $department_error = "Invalid department selection!<br>";// You can change this as required
     
    if($_SERVER['REQUEST_METHOD'] != 'POST'){
    $error = "No direct access allowed!";
    include $error_url;
    exit;
    }
     
    $mailfrom = isset($_POST['email']) ? $_POST['email'] : $mailto;
     
    $max_filesize = isset($_POST['filesize']) ? $_POST['filesize'] * 1024 : 1024000;
    $upload_folder = isset($_POST['upload_folder']) ? $_POST['upload_folder'] : "uploads";
    $upload_folder = "http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME'])."/".$upload_folder;
    session_start();
    if (isset($_SESSION['random_txt']) && md5($_POST['captcha_code']) == $_SESSION['random_txt']) {
    unset($_POST['captcha_code'],$_SESSION['random_txt']);
    }
    else {
    $error = "The verification code you have entered is not correct! Please go back and try again.";
    include $error_url;
    exit;
    }
    function RecursiveMkdir($path)
    {
    if (!file_exists($path))
    {
    RecursiveMkdir(dirname($path));
    mkdir($path, 0777);
    }
    }
    function check_email($string, $stringname)
    {
    $pattern = '/^([0-9a-z]([-.\w]*[0-9a-z])*@(([0-9a-z])+([-\w]*[0-9a-z])*\.)+[a-z]{2,6})$/i';
    if (!preg_match($pattern, $string)) {
    $error = "Your $stringname seems incorrect or missing!";
    }
    return $error;
    }
    $department = $_POST['department'];
    $mailto = $address[$department];
    if ($mailto == "") {
    $error = $department_error;
    }
     
    $header = "From: ".$mailfrom."\r\n";
    $header .= "Reply-To: ".$mailfrom."\r\n";
    $header .= "MIME-Version: 1.0"."\r\n";
    $header .= "Content-Type: text/plain; charset=utf-8"."\r\n";
    $header .= "Content-Transfer-Encoding: 8bit"."\r\n";
    $header .= "X-Mailer: PHP v".phpversion();
    $prefix = rand(111111, 999999);
    $i = 0;
    while (list ($key, $val) = each ($_FILES))
    {
    if ($_FILES[$key]['name'] != "" and file_exists($_FILES[$key]['tmp_name']) and $_FILES[$key]['size'] > 0)
    {
    $upload_DstName[$i] = $prefix . "_" . str_replace(" ", "_", $_FILES[$key]['name']);
    $upload_SrcName[$i] = $_FILES[$key]['name'];
    $upload_Size[$i] = ($_FILES[$key]['size']);
    echo "Uploaded File size = ".$upload_Size[$i] ."<br>]";
    $upload_Temp[$i] = ($_FILES[$key]['tmp_name']);
    $upload_Type[$i] = ($_FILES[$key]['type']);
    $uploadlink[$i] = "$upload_folder/$upload_DstName[$i]";
    $upload_fieldname[$i] = $key;
    $upload_fieldname_final[$i] = ucwords(str_replace("_", " ", $key));
    $fieldvalue[$i] = $uploadlink[$i];
    if ($upload_Size[$i] >= $max_filesize)
    {
    $error .= "The size of $key (file: $upload_SrcName[$i]) is bigger than the allowed " . $max_filesize/1024 . " Kbytes!\n";
    }
    }
    $i++;
    }
    $crack[0] = '\n';
    $crack[1] = '\r';
    $crack[2] = "%0a";
    $crack[3] = "%0d";
    $crack[4] = "content-type:";
    $crack[5] = "to:";
    $crack[6] = "cc:";
    $crack[7] = "bcc:";
    $crack[8] = "mime-version:";
    $crack[9] = "x0a";
    $crack[10] = "x0d";
    foreach ($_POST as $key => $value)
    {
    for ($k = 0; $k < count($crack); $k++)
    {
    if (substr_count(strtolower($value), $crack[$k]))
    {
    $error .= "The field $key contained e-mail headers ($crack[$k]) in the value submitted. This seems to be a cracking attempt and the message has not been sent.!<br>";
    }
    }
    }
    if (($_POST['email'])) {
    $error .= check_email($_POST['email'], "Email Address");
    }
    if ($error)
    {
    include $error_url;
    exit;
    }
    $uploadfolder = basename($upload_folder);
    for ($i = 0; $i < count($upload_DstName); $i++)
    {
    $uploadFile = $uploadfolder . "/" . $upload_DstName[$i];
    if (!is_dir(dirname($uploadFile)))
    {
    @RecursiveMkdir(dirname($uploadFile));
    }
    else
    {
    @chmod(dirname($uploadFile), 0777);
    }
    @move_uploaded_file($upload_Temp[$i] , $uploadFile);
    chmod($uploadFile, 0644);
    }
    $internalfields = array ("submit", "reset", "filesize", "upload_folder", "send", "captcha_code", "form_to");
    $message .= "\n";
    foreach ($_POST as $key => $value)
    {
    if (!in_array(strtolower($key), $internalfields))
    {
    if (!is_array($value))
    {
    $message .= ucwords(str_replace("_", " ", $key)) . " : " . $value . "\n";
    }
    else
    {
    $message .= ucwords(str_replace("_", " ", $key)) . " : " . implode(",", $value) . "\n";
    }
    }
    }
    if (count($upload_SrcName) > 0)
    {
    $message .= "\nThe following file have been uploaded:\n";
    for ($i = 0; $i < count($upload_SrcName); $i++)
    {
    $message .= $upload_SrcName[$i] . " Link: " . $uploadlink[$i] . "\n";
    }
    }
    mail($mailto, $subject, stripslashes($message), $header);
    ?>
    3. In the aboce code, you need to change the following parts, according to your needs (only parts in red, make sure to keep quotes as seen):

    $subject = 'New Submission from our Multiple Department Website form';// You can change this as required
    $message = 'Values submitted from web site form to department: '.$_POST['department'];// You can change this as required
    $error_url = 'errorpage.php'; // You can change this as required

    $address[Sales] = "sales@yourdomain.com";
    $address[Assistance] = "assistance@yourdomain.com";// You can change this as required
    $address[Accounting] = "accounting@yourdomain.com";// You can change this as required
    // Add as many similar lines as required

    $department_error = "Invalid department selection!<br>";// You can change this as required


    4. Create an errorpage named "errorpage". Needs to be .php Add your own template and the following text:

    ##error##

    which, in case of error, will be replaced by the actual error.

    "confirm" and "errorpage" can be changed as you like, as long as you replace these names also in the above code and settings.
    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

    • gillenium
      Sergeant

      • Dec 2008
      • 27

      #3
      Re: One contact form with multiple e-mail options to submit to

      THANK YOU!!!

      I have a glitch somewhere though. When I Submit the information on the form, my confirm.php page url shows in the address bar but it is the error page that shows on the screen. Also, the information I submitted is not e-mailed to the address I provided. Here's what I did....I did #1 creating the form no problem and verified that the name of the combobox is department. I also named the form department. Is this ok?

      Next, I created the Thank You page, named it confirm and its extension is .php . I then copied the html code you provided and pasted it in the start of page tab of the page html. I then changed the subject text a little but kept the single quotes. I kept the message and error_url information the same.

      Next, I changed the department names to reflect the names I created in the combobox on the form. For example I changed [Sales] to [Otterskin_Roof_Gear] etc. and then the corresponding e-mail addresses while still keeping the brackets and the quotes. I did the same for Warranty and Manufacturing and then added two more lines by copying, pasting and changing just the name and the e-mail address.

      Finally, I created errorpage with the .php extension. I'm assuming the html code is not supposed to be in the page html. Not sure if I did something right here though. Where am I supposed to enter the ##error## test? I just created a line of text on the page and typed in ##error##. WHen this page is pooping up, that text didn't change so I am wondering if I was supposed to add it somewhere else.

      The page I created is just a copy of my Contact Us page for right now untill I get the bugs worked out and then will build it to what I need. But if you go to http://www.helpingusellu.com/contact-department.php and select a department and type a comment, when you click on SUBMIT, you'll see what I explained above.

      Any idea what's happening?

      Thanks!
      Scott

      Comment

      • navaldesign
        General & Forum Moderator

        • Oct 2005
        • 12080

        #4
        Re: One contact form with multiple e-mail options to submit to

        It is normal that the error page appears whilst in the address bar you have the "thankyou" page URL. This happens because if an error is encountered, the script recalls the error page WITHIN the thankyou one.

        The text ##error## : Sorry, this is my mistake.

        Place this text in the error page:

        '.$error.'

        Including the quotes.
        Right click it, and add the following in its HTML:

        In the Before Tag:

        <?php
        echo '

        In the After Tag:

        ';
        ?>

        If you do so, it will display the actual error so we will know what's wrong.
        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

        • gillenium
          Sergeant

          • Dec 2008
          • 27

          #5
          Re: One contact form with multiple e-mail options to submit to

          Got it! The error message that appears on the error page is..."The verification code you have entered is not correct! Please go back and try again."

          What do I need to do with this?

          Comment

          • navaldesign
            General & Forum Moderator

            • Oct 2005
            • 12080

            #6
            Re: One contact form with multiple e-mail options to submit to

            Please replace, in the code,

            if (isset($_SESSION['random_txt']) && md5($_POST['captcha_code']) == $_SESSION['random_txt']) {
            unset($_POST['captcha_code'],$_SESSION['random_txt']);
            }
            else {
            $error = "The verification code you have entered is not correct! Please go back and try again.";
            include $error_url;
            exit;
            }



            with:



            if (isset($_POST['captcha_code'])) {
            if ($_POST['captcha_code'] == $_SESSION['random_txt'])
            {
            unset($_POST['captcha_code'],$_SESSION['random_txt']);
            }
            else
            {
            $error = "The verification code you have entered is not correct! Please go back and try again. ";

            include $error_url;
            exit;
            }
            }

            The code, as was, was ment to have a mandatory captcha (which you don't have)
            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

            • gillenium
              Sergeant

              • Dec 2008
              • 27

              #7
              Re: One contact form with multiple e-mail options to submit to

              I wondered if that might have been it. I made the above changes and it looks like it fixed that error. However, I am now getting an error that reads "Invalid department selection!" In case it has something to do with the areas that I changed relating to the various departments, here is that area of code that I currently have inserted:


              $subject = 'Selling U Department Request';
              $message = 'Values submitted from web site form to department: '.$_POST['department'];
              $error_url = 'errorpage.php';

              $address[Otterskin_Roof_Gear] = "otterskin@xxxxxxxx.com";
              $address[Selling_U] = "workinghard@xxxxxxxx.com";
              $address[Gillenium] = "gillenium@xxxxxxxx.com";
              $address[Carol_Feltman] = "feltman37@xxxxxxxx.com";
              $address[Brittany_Lewis] = "jedi.180@xxxxxxxx.com";
              $department_error = "Invalid department selection!<br>";


              I'm only getting the error with the departments that contain multiple words. (e.g. Otterskin Roof Gear). The Gillenium selection works fine and receives the e-mailed information. I originally had the names without underscores, but I would get a parsed code message that appears when I click Submit. Adding the underscores (or dashes) between the words at least gets me to the error page. Eliminating the space, underscores and dashes (e.g. OtterskinRoofGear) doesn't work either.

              Is there something in this area I need to tweak or what else would be triggering this error?

              Thanks again,
              Scott

              Comment

              • navaldesign
                General & Forum Moderator

                • Oct 2005
                • 12080

                #8
                Re: One contact form with multiple e-mail options to submit to

                If you try Gillenium, it works.
                The others will not work because in the script you have "Otterskin_Roof_Gear" but in the listbox you have "Otterskin Roof Gear" and so on:

                <option>Please Select a Recipient</option>
                <option>Otterskin Roof Gear</option>
                <option>Selling U</option>
                <option>Gillenium</option>
                <option>Carol Feltman</option>
                <option>Brittany Lewis</option>

                Note underscores against whitespaces.

                Also, you should actually give, in your listbox, also the item name AND the value, not just one of the two
                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

                • gillenium
                  Sergeant

                  • Dec 2008
                  • 27

                  #9
                  Re: One contact form with multiple e-mail options to submit to

                  I originally had the html department names with white spaces instead of the underscores. If I remove the underscores from the department names and type them out the way they appear in the form on the site - with white spaces - this is the error message I get. (Note: This message appears on a white screen in the browser - not on the errorpage from my website.)


                  Parse error: syntax error, unexpected T_STRING, expecting ']' in /home/ygyefcpm/public_html/confirm.php on line 7

                  But when I add the underscores, it at least takes me to my site with the error message of the Invalid Department Sellection.

                  I'm not sure what you mean by this "Also, you should actually give, in your listbox, also the item name AND the value, not just one of the two" Are you talking about the department name in the combobox that you can select from on the site? I'm assuming the item name would be the department name. What would I include after it as its value?

                  Comment

                  • gillenium
                    Sergeant

                    • Dec 2008
                    • 27

                    #10
                    Re: One contact form with multiple e-mail options to submit to

                    I replaced the underscores with white spaces and published the page so you can see what I described.

                    By the item and value, do you mean to include the department name (as the item) and the department's e-mail address (as the value) right in the combobox so both are seen when a visitor clicks on the drop-down to select?

                    Comment

                    • navaldesign
                      General & Forum Moderator

                      • Oct 2005
                      • 12080

                      #11
                      Re: One contact form with multiple e-mail options to submit to

                      No, I mean that both the item name and the Value, for each of the options of the select box, need to be the same. That is, you repeat it twice.

                      Try also placing quotes as follows:

                      $address['Otterskin_Roof_Gear'] = "otterskin@xxxxxxxx.com";
                      $address['Selling_U'] = "workinghard@xxxxxxxx.com";
                      $address['Gillenium'] = "gillenium@xxxxxxxx.com";
                      $address['Carol_Feltman'] = "feltman37@xxxxxxxx.com";
                      $address['Brittany_Lewis'] = "jedi.180@xxxxxxxx.com";
                      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

                      Working...
                      X