On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • hello,

    the postHook works not sad
    http://rtfm.modx.com/display/ADDON/Login.Using+Pre+and+Post+Hooks

    i have login/register page.. everything works. but i want to send to admin an email also. Not only a bcc.. that works.

    but i use "SMTP=Yes".. is that the reason, why the postHook
    $message = 'Hi, a new User signed up: '.$hook->getValue('username')
     . ' with email '.$hook->getValue('email').'.';
     
    $modx->getService('mail', 'mail.modPHPMailer');
    $modx->mail->set(modMail::MAIL_BODY,$message);
    $modx->mail->set(modMail::MAIL_FROM,'admin@jerrys.org');
    $modx->mail->set(modMail::MAIL_FROM_NAME,'Jerrys Site');
    $modx->mail->set(modMail::MAIL_SENDER,'Jerrys Site');
    $modx->mail->set(modMail::MAIL_SUBJECT,'New User Signed Up');
    $modx->mail->address('to','communitymanager@jerrys.com');
    $modx->mail->setHTML(true);
    if (!$modx->mail->send()) {
        $modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$err);
    }
    $modx->mail->reset();
    /* tell our snippet we're good and can continue */
    return true;


    not works?

    please help
    • This is what I have that works
      [[!Register? .... &postHooks=`notifyAdmin` ]]
      //I place notifyAdmin at the very end.
      notifyAdmin
      $message = 'Hi, a new User signed up: '.$hook->getValue('username')
       . ' with email '.$hook->getValue('email').'.';
       
      $modx->getService('mail', 'mail.modPHPMailer');
      $modx->mail->set(modMail::MAIL_BODY,$message);
      $modx->mail->set(modMail::MAIL_FROM,'visitor@gmail.com');
      $modx->mail->set(modMail::MAIL_FROM_NAME,'myGmail Auto');
      $modx->mail->set(modMail::MAIL_SENDER,'myGmail Auto');
      $modx->mail->set(modMail::MAIL_SUBJECT,'New User Signed Up');
      $modx->mail->address('to','personal@gmail.com');
      $modx->mail->setHTML(true);
      if (!$modx->mail->send()) {
          $modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$err);
      }
      $modx->mail->reset();
      /* tell our snippet we're good and can continue */
      return true;
        TinymceWrapper: Complete back/frontend content solution.
        Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
        5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
      • Strange this does not work for me...

        Everything else is working perfectly... how can this be?

        Error in error log (empty!):
        [2016-07-11 12:06:26] (ERROR @ /var/sites/m/moorparknorthwoodhouses.forsale/public_html/core/cache/includes/elements/modsnippet/62.include.cache.php : 13) An error occurred while trying to send the email: 


        Register code:
        [[!Register?
            &submitVar=`registerbtn`
            &activationResourceId=`14`
            &activationEmailTpl=`ActivationEmailTpl`
            &activationEmailSubject=`Thanks for Registering!`
            &submittedResourceId=`13`
            &usergroups=`Members`
            &validate=`nospam:blank,
        		username:required:minLength=^6^,
        		password:required:minLength=^6^,
        		password_confirm:password_confirm=^password^,
        		fullname:required,
        		email:required:email`
            &placeholderPrefix=`reg.`
            &successMsg=`Thanks for registering!`
            &postHooks=`notifyAdmin`
        ]]
        


        notifyAdmin snippet:
        $message = 'Hi, a new User signed up: '.$hook->getValue('username')
         . ' with email '.$hook->getValue('email').'.';
        $modx->getService('mail', 'mail.modPHPMailer');
        $modx->mail->set(modMail::MAIL_BODY,$message);
        $modx->mail->set(modMail::MAIL_FROM,'visitor@gmail.com');
        $modx->mail->set(modMail::MAIL_FROM_NAME,'myGmail Auto');
        $modx->mail->set(modMail::MAIL_SENDER,'myGmail Auto');
        $modx->mail->set(modMail::MAIL_SUBJECT,'New User Signed Up');
        $modx->mail->address('to','personal@gmail.com');
        $modx->mail->setHTML(true);
        if (!$modx->mail->send()) {
            $modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$err);
        }
        $modx->mail->reset();
        /* tell our snippet we're good and can continue */
        return true;
        
          MODX Ambassador (NL) | Responsive web design specialist, developer & speaker
          DESIGNfromWITHIN, MPThemes and Any Screen Size
          Follow me on Twitter | Read my blog | My code on GitHub
        • Does the notifyAdmin snippet work when you use it outside of Register?

          This could be a problem since Gmail may see the email as being sent from the site's domain rather than gmail.com:

          $modx->mail->set(modMail::MAIL_FROM,'visitor@gmail.com');


          Another thought: Gmail will silently drop *all* mail from some hosts. I had this problem with BlueHost. It's caused by the host forwarding all mail without running it through a spam filter first. It's part of the reason I set up Notify to send through Mandrill or Mailgun.

          You could also try setting up QuickEmail with the same email field values you're using above, to see if that works.

          This is a separate issue, but it may come into play if you get things working: http://bobsguides.com/blog.html/2016/07/09/prevent-email-warning-from-gmail/ [ed. note: BobRay last edited this post 4 years, 2 months 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