We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18902
    • 7 Posts
    I was wondering how to set up the eform to send an email to various email addresses based on the subject selected.

    So if the user selects the ’General Inquiries’ drop down, the email is sent to [email protected]
    else if the user sends to ’Sales Inquiries’ the email is sent to [email protected]

    Here’s my little if else statement.

    if($subject == ’General Inquiries’){
    $to = ’[email protected]’;
    }else if($subject == ’Sales Inquiries’){
    $to = ’[email protected]’;
    }



    Thanks for your help in advance

    James
      • 19726
      • 239 Posts
      It sounds like you could just use the &mailselector option from eForm. See the following section from the eForm documentation.

      ---

      &mailselector (Optional)
      Sets the name of the form field to use as a selector to select a single email from the comma (,) delimited emails assigned the &toparameter. This selector field will act like a numeric index to select an email. It will start at 1 for the first email and ends at N for the last email in the list.

      For example: &to =`[email protected],[email protected],[email protected]` &mailselector=`topic`

      On the web form the topic fields is actually a dropdown menu. when the user selects a topic from the list the value 1,2 or 3 will be sent to eForm which will then be used to select one of the three emails assigned to the &to parameter. This email address will be the address used to send the email to.
        • 18902
        • 7 Posts
        Thanks for your help, unfortunately the email is sending out to all recipients regardless of the topic chosen.

        The email looks like this
        To: [email protected], me@mydomain

        Here’s the call I’m using
        [!eForm? &formid=`ContactForm` &subject=`[+subject+]` &to=`[email protected],[email protected]` &mailselector=`topic` &ccsender=`1` &tpl=`ContactForm` &report=`ContactFormReport` &invalidClass=`invalidValue` &requiredClass=`requiredValue` &cssStyle=`ContactStyles` &gotoid=`46` !]

        Am I doing something wrong here?
          • 30223
          • 1,010 Posts
          Can you post your form template please?
            • 18902
            • 7 Posts
            <p class="error">[+validationmessage+]</p>

            <form method="post" action="[~[*id*]~]" id="EmailForm" name="EmailForm">

            <fieldset>

            <input name="formid" type="hidden" value="ContactForm" />

            <label for="cfName">Your name:
            <input name="name" id="cfName" class="text" type="text" eform="Your Name::1:" /> </label>

            <label for="cfEmail">Your Email Address:
            <input name="email" id="cfEmail" class="text" type="text" eform="Email Address:email:1" /> </label>

            <label for="cfRegarding">Regarding:</label>
            <select name="subject" id="cfRegarding" eform="Form Subject::1">
            <option value="General">General Inquiries</option>
            <option value="Sales">Website Sales Inquiries</option>
            </select>

            <label for="cfMessage">Message:
            <textarea name="message" id="cfMessage" rows="4" cols="20" eform="Message:textarea:1"></textarea>
            </label>

            <label>&nbsp;</label><input type="submit" name="contact" id="cfContact" class="button" value="Send This Message" />

            </fieldset>

            </form>
              • 30223
              • 1,010 Posts
              Do you understand what happens if you set &mailselector=`topic`? Looks like you don’t as there is no topic field in your form.

              Read this again and again until you understand smiley
              &mailselector
              Sets the name of the form field to use as a selector to select a single email from the comma (,) delimited emails assigned the &to parameter. This selector field will act like a numeric index to select an email. It will start at 1 for the first email and ends at N for the last email in the list.

              You want the customer to select from what is now the subject field and base the email address on that. This means the subject field needs to return a number (as stated above) in order to choose the correct email address. As "subject" has a special meaning in eForm you should rename the field to something else. Let’s stick to "topic" as that’s what you already have in your snippet call. So change your dropdown to this:

               <select name="topic" id="cfRegarding" eform="Form Subject::1">
                       <option value="1">General Inquiries</option>
                       <option value="2">Website Sales Inquiries</option>
                    </select>
              


              This should solve the email address problem but you now don’t have a subject for your email. Sadly it’s either one or the other. Luckily you can set the &subject parameter. For instance &subject=`website enquiry`. Or you can create a subject form text field which the customer can fill in.

                • 18902
                • 7 Posts
                Great problem solved, and I’ve taken one unhappy face on the chin. Thanks. wink