We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8168
    • 1,118 Posts
    Hi,

    I have a formit form, which is using a custom redirect hook to send people to either redirect page A or B based on the fields they complete in the form. If the user is redirected to page A - then I need to add in some PHP code to fire off an email with details of the form fields completed - else, if they are redirected to page B, I need to pass the data to the next page which is a login register form - where I will then store this initial formit form data as custom fields...

    Is this possible? If so any tips on how???

    Cheers

    dubbs.
      • 3749
      • 24,544 Posts
      I think your best bet is to get the data with $hook->getValue() in the custom redirect hook and save it as variables in the $_SESSION array.

      $_SESSION['email'] = $hook->getValue('email'); /* (off the top of my head. May not be quite correct) */


      Then you can retrieve the values in a snippet on page A or page B (using a Register preHook on page B to set the placeholders):

      $email = $_SESSION['email'];


      You could also use FormItRetriever, but I think the $_SESSION approach is a lot easier to implement.

      Sending an email is pretty straightforward. There's example code at the end of this page.





        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
        • 8168
        • 1,118 Posts
        Thanks Bob. Will give it a go!
          • 8168
          • 1,118 Posts
          Quote from: BobRay at Aug 16, 2016, 04:00 PM
          I think your best bet is to get the data with $hook->getValue() in the custom redirect hook and save it as variables in the $_SESSION array.

          $_SESSION['email'] = $hook->getValue('email'); /* (off the top of my head. May not be quite correct) */


          Then you can retrieve the values in a snippet on page A or page B (using a Register preHook on page B to set the placeholders):

          $email = $_SESSION['email'];


          You could also use FormItRetriever, but I think the $_SESSION approach is a lot easier to implement.

          Sending an email is pretty straightforward. There's example code at the end of this page.






          Bob - Using QuickEmail snippet - can I define a Chunk to use for the message body of the email? I need to pass PHP variables into it and mix it with some plain HTML elements...?
            • 8168
            • 1,118 Posts
            Quote from: dubbs at Aug 17, 2016, 04:22 AM
            Quote from: BobRay at Aug 16, 2016, 04:00 PM
            I think your best bet is to get the data with $hook->getValue() in the custom redirect hook and save it as variables in the $_SESSION array.

            $_SESSION['email'] = $hook->getValue('email'); /* (off the top of my head. May not be quite correct) */


            Then you can retrieve the values in a snippet on page A or page B (using a Register preHook on page B to set the placeholders):

            $email = $_SESSION['email'];


            You could also use FormItRetriever, but I think the $_SESSION approach is a lot easier to implement.

            Sending an email is pretty straightforward. There's example code at the end of this page.






            Bob - Using QuickEmail snippet - can I define a Chunk to use for the message body of the email? I need to pass PHP variables into it and mix it with some plain HTML elements...?

            Worked it out wink
              • 8168
              • 1,118 Posts
              Bob - does the QuickMail snippet support BCC?
                • 3749
                • 24,544 Posts
                You don't need to use the snippet, just the code at the end. BCC should work fine.

                I think this is what you need:

                $modx->mail->address('bcc', '[email protected]');
                  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
                  • 8168
                  • 1,118 Posts
                  Quote from: BobRay at Aug 18, 2016, 12:10 AM
                  You don't need to use the snippet, just the code at the end. BCC should work fine.

                  I think this is what you need:

                  $modx->mail->address('bcc', '[email protected]');

                  Hi Bob - sorry, I don't think you understood my question. I am using the code as below and need to be able to add a BCC address in the parameters - can you advise how to do that?

                  $props = array(
                      'debug' => '0',
                      'hideOutput' => '0',
                      'message' => $FailEmailMessage,
                      'subject' => 'Email title',
                      'to' => '[email protected]',
                      'bcc' => '[email protected]',
                      'fromName' => 'Dave',
                      'emailSender' => '[email protected]',
                      'replyTo' => '[email protected]',
                      'html' => '1',
                      'failureMessage' => '<br /><h3 style="color:red">Mail Failed</h3>',
                      'successMessage' => '<br /><h3 style ="color:green">Mail reported successful</h3>',
                      'errorHeader' => '<br />Mail error:',
                      'smtpErrorHeader' => '<br />SMTP server report:',
                  );
                  
                  $output =  $modx->runSnippet('QuickEmail',$props);
                  return $output;
                  
                    • 3749
                    • 24,544 Posts
                    Ah, I see your problem. QuickEmail is mainly meant as a diagnostic program. It doesn't handle bcc or cc.

                    You could add this code to the snippet around line 82

                    $cc = $modx->getOption('cc', $sp, '');
                    $bcc = $modx->getOption('bcc', $sp, '');


                    And this code around line 143:

                    if (! empty ($cc))  {
                        $modx->mail->address('cc', $cc);
                    }
                    
                    if (!empty ($bcc)) {
                        $modx->mail->address('bcc', $bcc);
                    }


                    Then, your code above should work (assuming that I have the case of the cc and bcc correct).

                    Let me know if it works. If it does, I'll add it to the next release.
                    [ed. note: BobRay last edited this post 10 years, 1 month ago.]
                      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
                      • 8168
                      • 1,118 Posts
                      Thanks Bob - will give it a go and let you know.