We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37619
    • 79 Posts
    I'm working on a MODX Revo 2.5.1-pl installation with FormIt 2.2.11-pl installed

    Hi there!

    I've created a FormIt hook that sets the value of the emailTo parameter based on another parameter:
    FormIt call:
    [[!FormIt? emailTo=`[[+emailRecipient]]`]]

    Snippet:
    $hook->setValue('emailRecipient', '[email protected]');
    $email_recipient = $hook->getValue('emailRecipient');
    error_log($email_recipient);
    // returns [email protected]
    

    This code above works like a charm (obviously the FormIt call has a bunch more parameters). The emailTo parameter gets set to [email protected] without any issues.

    However, if I change the snippet to multiple addresses that are comma-separated (with or without a space), I get an error:
    Snippet:
    $hook->setValue('emailRecipient', '[email protected],[email protected]');
    $email_recipient = $hook->getValue('emailRecipient');
    error_log($email_recipient);
    // returns [email protected],[email protected]
    


    As you can see in the code above, both emails get passed into the emailRecipient field as it displays within the server error log.
    However, I'm getting the following error in the MODX error log:
    (ERROR @ mysite.com/core/components/formit/model/formit/fihooks.class.php : 552) [FormIt] An error occurred while trying to send the email. You must provide at least one recipient email address.

    You must provide at least one recipient email address even though 2 addresses are being provided. I've tried it with 3 email addresses and got the same result, but again, this worked perfectly fine when there's only one email address.

    This leads me to believe that the issue comes from FormIt, but this is where I'm stuck and coming here for help.

    Finally, the weirdest thing of all is that if I put multiple email addresses in the emailTo parameter of the FormIt call, it works!
    [[!FormIt? &emailTo=`[email protected],[email protected]`]]
    


    Go figure.

    Any leads or insight would be greatly appreciated.

    Thank you!
    jm
      Jean-Marc Buytaert (@jmbuytaert)

      MODX truly is the greatest thing that's ever happened to the Internet.
      • 3749
      • 24,544 Posts
      This is a known problem with FormIt. You can use the &emailCC or &emailBCC properties as a workaround. I think they will take a comma-separated list but I'm not positive.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
      • Try to modify the formit property directly in the hook:

        $hook->formit->options['emailTo'] = '[email protected],[email protected]';
        [ed. note: Jako last edited this post 7 years, 7 months ago.]
          • 37619
          • 79 Posts
          Hi Jako!
          Quote from: Jako at Oct 18, 2016, 11:58 PM
          Try to modify the formit property directly in the hook:
          $hook->formit->options['emailTo'] = '[email protected],[email protected]';
          I've tried this and I'm still getting the same result.

          Hi Bob!
          Quote from: BobRay at Oct 18, 2016, 11:41 PM
          This is a known problem with FormIt. You can use the &emailCC or &emailBCC properties as a workaround. I think they will take a comma-separated list but I'm not positive.
          Unfortunately the client would like the emailTo parameter to be both email addresses.

          Upon further research, I've added a few error_logs in the formIt core files (/core/components/formit/model/formit/fihooks.class.php) and discovered the following: for whatever reason it may be, the multiple email addresses are not being sent over to emailRecipient.

          I'll try to convince the client to use the emailCC and emailBCC parameters.

          Thank you both for your input!
          jm
            Jean-Marc Buytaert (@jmbuytaert)

            MODX truly is the greatest thing that's ever happened to the Internet.
          • Quote from: jmbuytaert at Oct 19, 2016, 06:35 PM
            Quote from: Jako at Oct 18, 2016, 11:58 PM
            Try to modify the formit property directly in the hook:
            $hook->formit->options['emailTo'] = '[email protected],[email protected]';
            I've tried this and I'm still getting the same result.

            This should work absolutely the same as adding the value to the snippet options. I think you have an issue in the hooks then. The email hook has to run after your custom hook that sets the emailTo.
              • 37619
              • 79 Posts
              Here's more debugging information - unfortunately, no solution yet:

              Quote from: Jako at Oct 20, 2016, 03:35 PM
              Quote from: jmbuytaert at Oct 19, 2016, 06:35 PM
              Quote from: Jako at Oct 18, 2016, 11:58 PM
              Try to modify the formit property directly in the hook:
              $hook->formit->options['emailTo'] = '[email protected],[email protected]';
              I've tried this and I'm still getting the same result.

              This should work absolutely the same as adding the value to the snippet options. I think you have an issue in the hooks then. The email hook has to run after your custom hook that sets the emailTo.
              I agree, this should absolutely work, but I'm still not being redirected to the thank you form, and I'm still not receiving the emails. He is my code below:

              Snippet:
              <?php
              error_log("hook1: ".$hook->formit->options['emailTo']);
              
              // Pull Division and Region selected from Form
              $np_msds = $hook->getValue('request-msds');
              
              // Get email address based whether or not SDS checkbox is selected
              if($np_msds == "yes"){
                  $hook->formit->options['emailTo'] = "[email protected],[email protected]";
                  error_log("hook form1: ".$hook->formit->options['emailTo']);
              } else {
                  $hook->formit->options['emailTo'] = "[email protected]";
                  error_log("hook form2: ".$hook->formit->options['emailTo']);
              }
              
              error_log("hook last: ".$hook->formit->options['emailTo']);
              error_log("******************** SNIPPET ENDS");
              
              return true;
              


              The hook is the first one being called:
              [[!FormIt? ... &hooks=`mySnippet,email`]]
              


              Server's Error Log:
              ******************** SNIPPET BEGINS, referer: http://mysite.com/page.html
              hook1: , referer: http://mysite.com/page.html
              hook form1: [email protected],[email protected], referer: http://mysite.com/page.html
              hook last: [email protected],[email protected], referer: http://mysite.com/page.html
              ******************** SNIPPET ENDS, referer: http://mysite.com/page.html
              


              /core/cache/logs/error.log:
              [2016-10-20 16:15:11] (ERROR @ /var/www/vhosts/mysite.com/core/components/formit/model/formit/fihooks.class.php : 379) [FormIt] Please specify a recipient or recipients for the email.
              


              So, this shows that the emails are being sent to FormIt's &emailTo= parameter, but for some reason, they're not being processed into FormIt.

              I think that for now, I'm just going to add the email addresses to emailCC and emailBCC if the condition is right. If you figure out what's wrong, please let me know, I'd love to know!

              Thanks,
              jm
                Jean-Marc Buytaert (@jmbuytaert)

                MODX truly is the greatest thing that's ever happened to the Internet.
                • 38666
                • 98 Posts
                Having the same problem but with a single email recipient. Has anyone found an answer?
                Snippet load-opc-em
                <?php
                $path = MODX_CORE_PATH . 'components/opc_database/';
                $result = $modx->addPackage('opc_database',$path . 'model/','');
                 
                if (! $result) {
                    return 'failed to add package';
                } else {
                 $pe = $_GET["pe"];
                 $opc_ID = trim($pe);
                // $opc_ID = 11;
                
                $opc = $modx->getObject('Person', array('PKPersonId' =>  $opc_ID));
                
                $emd = $opc->get('PersonEmailDomain');
                $emp = $opc->get('PersonEmail');
                //
                $opc_em = $emp."@".$emd;
                $spf_opc = "OPC: ".$opc_em;
                //
                $emto = trim($opc_em);
                $modx->setPlaceholder('addressTo',$emto);
                
                $modx->setPlaceholder('opc_addressTo',$spf_opc);
                $hook->formit->options['emailTo'] = $emto;
                }
                return true;
                

                Formit
                [!FormIt? 
                    $prehooks = `load-opc_em`
                	&hooks=`email,redirect` 
                	&emailTpl=`MyTestEmailChunk` 
                        &emailSubject=`Website Query`
                	&redirectTo=`81`
                ]]
                
                <h2>Contact Form</h2><div class="well">
                 
                <form action="[[~[[*id]]]]" method="post">
                     
                    <input type="text" name="opcname" value="[[+opcname]] [[!+fi.opcname]]" class="input-block-level">
                    <div id="name">
                        <label for="name">Name:</label>
                        <div class="controls">
                            <input type="text" name="name" value="[[!+fi.name]]" class="input-block-level">
                        </div>
                    </div>
                 
                    <div id="email">
                        <label for="email">Email:</label>
                        <div class="controls">
                            <input type="text" name="email" value="[[!+fi.email]]" class="input-block-level">
                        </div>
                    </div>
                 
                    <div id="comment">
                        <label for="comment">Comment:</label>
                        <div class="controls">
                            <textarea name="comment" cols="30" rows="10" value="[[!+fi.comment]]" class="input-block-level"></textarea>
                        </div>
                    </div>
                 
                    <input type="submit" value="Submit" class="btn btn-primary">
                 
                 
                </form>
                 
                </div>
                  Give a man the answer, and he’ll only have a temporary solution. Teach him the principles that led you to that answer, and he will be able to create his own solutions in the future.
                  • 54308
                  • 9 Posts
                  Quote from: BobRay at Oct 18, 2016, 11:41 PM
                  This is a known problem with FormIt. You can use the &emailCC or &emailBCC properties as a workaround. I think they will take a comma-separated list but I'm not positive.

                  This does not seem to work either - at least not if you try to do this dynamically. I tried using jquery to populate a hidden form field based upon selections on the form. The form field was passed to the &emailCC. If the form field contains multiple email addresses, the email still gets sent but not to anyone in the field passed to &emailCC. So it doesn't keep the form from being submitted like &emailTo. It just doesn't make it to anyone in the emailCC list.

                  I have a matrix of from 2 to 7 emails that I need to send a given form submission. Two of those emails are selected from a group of 17 email addresses based upon the state and county selected on the form. One of those two will have to be sent via the CC and the other the BCC. The &emailTo field will have to use a form field that is coded to contain one of 3 different web addresses that point to an exchange public folder. Each public folder will have a different forward to rule set up. This is the only way I can see of doing this and still use formit.
                    • 3749
                    • 24,544 Posts
                    Just one reason why I don't use FormIt. wink
                      Did I help you? Buy me a beer
                      Get my Book: MODX:The Official Guide
                      MODX info for everyone: http://bobsguides.com/modx.html
                      My MODX Extras
                      Bob's Guides is now hosted at A2 MODX Hosting
                      • 46886
                      • 1,154 Posts
                      What is the better solution than formit?