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
    Quote from: BobRay at Oct 20, 2014, 10:22 PM
    Don't thank me until it works. wink

    ;) Thanks Bob - Afraid still not working - not sure why - the update function now works - I added in a
    return true;
    to the end of each snippet by the way - the update does not, but it does not output the output variable to show what has changed - What I'd like is to have the output of the update passed into the mail sending code I am using. I have pasted this below:

    $headers .= "From: Website<[email protected]>\n";
    $headers .= "BCC: <[email protected]>\n";
    $headers .= "Content-Type: text/html; charset=iso-8859-1\n"; //
     
    $message = '
     
    <p>A member has recently updated their membership details. Details of the user who has updated their profile details are outlined below:</p>
     
    <p>Full Name: <strong>'.$hook->getValue('fullname'). '</strong></br>
    Email Address: <strong>'.$hook->getValue('email').'</strong></p>
    
    <p>$output;</p>
    
    <p> </p> 
    <p>The website team.</p>
     
    ';
     
    $to = "[email protected]";
    $subject = "Member profile update changes notification";
     
     
     if (mail($to, $subject, $message, $headers)) {
       echo("<p>Message successfully sent!</p>");
      } else {
       echo("<p>Message delivery failed...</p>");
      }
    
    /* tell our snippet we're good and can continue */
    return true;
    
      • 3749
      • 24,544 Posts
      How about putting the mail sending code at the end of the postHook I wrote?

      The $output variable won't be set in another snippet.
        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
        Yeh I tried that - didn't work unfortunately...
          • 3749
          • 24,544 Posts
          When you tried it, was the email sent, and if so, what did it look like?
            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 Oct 22, 2014, 09:30 PM
            When you tried it, was the email sent, and if so, what did it look like?

            Nothing happens Bob - On click of sumbit to update the member profile details, the screen goes blank - don't get the update successful message, no email is fired. The updates are saved to the DB however...
              • 3749
              • 24,544 Posts
              If you put the email code in a separate snippet (not a postHook), does it send mail?
                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 Oct 23, 2014, 07:43 PM
                If you put the email code in a separate snippet (not a postHook), does it send mail?

                The email code is fine, that works, I currently use it as the postHook and it sends a generic note about a user updating their profile - the issue is that the preHook and postHook you created don't seem to work... sorry Bob... Do you have it working on an install somewhere I can take a look at? Really do appreciate your help here!
                  • 3749
                  • 24,544 Posts
                  Sorry, no. I've never done anything similar that I can recall.

                  Can you post the full code of the postHook with the email in it? A PHP syntax error could be stopping the whole thing from working.

                    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 Oct 23, 2014, 08:46 PM
                    Sorry, no. I've never done anything similar that I can recall.

                    Can you post the full code of the postHook with the email in it? A PHP syntax error could be stopping the whole thing from working.


                    Here we go - postHook code as below, this code doesn't include the email bit, but it's not even working like this I don't think - when you his submit to change profile updates - the page goes blank - I can't see the updates confirmed label or the output to show what profile fields were updated. Think the issues are in this not the email bit...

                    I was trying to output the content of the output variable to the error console...

                    
                    <?php
                    $oldProfile = isset($_SESSION['user_profile'])
                        ? $_SESSION['user_profile']
                        : array();
                    $profile = $modx->user->getOne('Profile');
                    if ($profile) {
                        $newProfile = $profile->toArray();
                    }
                    $output = '';
                     
                    if (!empty($newProfile) && (!empty($oldProfile))) {
                     
                        foreach ($newProfile as $key => $value) {
                            if ($oldProfile['key'] != $newProfile['key']) {
                                $output .= '<br />' . $key . ' changed from ' . $oldProfile['key'] . ' to ' . $newProfile['key'];
                            }
                        }
                    }
                    if (!empty($output)) {
                        $output = '<br />Changes:<br />' . $output;
                    } else {
                        $output = '<br />Changes: none<br />';
                    }
                     
                    /* Change report will be in the $output variable here */
                    
                    
                    $modx->log(modX::LOG_LEVEL_ERROR,'Profile update: $output'.$err);
                    
                    /* tell our snippet we're good and can continue */
                    return true;
                    
                    
                      • 3749
                      • 24,544 Posts
                      Nothing wrong with the code that I can see.

                      Try this:

                      <?php
                      $oldProfile = isset($_SESSION['user_profile'])
                          ? $_SESSION['user_profile']
                          : array();
                      $profile = $modx->user->getOne('Profile');
                      if ($profile) {
                          $newProfile = $profile->toArray();
                      }
                      $output = '';
                      
                      if (!empty($newProfile) && (!empty($oldProfile))) {
                      
                          foreach ($newProfile as $key => $value) {
                              if ($oldProfile['key'] != $newProfile['key']) {
                                  $output .= '<br />' . $key . ' changed from ' . $oldProfile['key'] . ' to ' . $newProfile['key'];
                              }
                          }
                      }
                      if (!empty($output)) {
                          $output = '<br />Changes:<br />' . $output;
                      } else {
                          $output = '<br />Changes: none<br />';
                      }
                      
                      if (! empty($output)) {
                          die($output);
                      } else {
                          die('Output is empty');
                      }
                      /* Change report will be in the $output variable here */
                      
                      
                      $modx->log(modX::LOG_LEVEL_ERROR, 'Profile update: $output' . $err);
                      
                      /* tell our snippet we're good and can continue */
                      return true;
                        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