We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40122
    • 330 Posts
    I am trying to send a 2nd email to my sites admin when a user registers.

    I made a postHook snippet that sends an email but it didnt work - the Registration process worked as expected, but I got no 2nd email from the hook.

    In testing I set the hook from postHook to preHook and tried again - this time the form didnt process at all - no new user was created and no activation email was sent. It didnt even redirect to the submittedResourceId.

    So, I deleted everything in my preHook Snippet, except the 'return true;' and tried again - still nothing.

    It appears Login wont run any Hooks at all. I have no idea why.

    Would anyone be able to suggest any fixes?

    My Register call is:

    [[!Register?
        &submitVar=`registerbtn`
        &activationResourceId=`19`
        &activationEmailTpl=`lgnActivateEmailTpl`
        &activationEmailSubject=`Thanks for Registering!`
        &submittedResourceId=`23`
        &usergroups=`2`
        &validate=`nospam:blank,
        username:required:minLength=^6^,
        password:required:minLength=^6^,
        password_confirm:password_confirm=^password^,
        fullname:required,
        email:required:email`
        &preHooks=`adminEmailHook`
    ]]


    (I am running Revo 2.3.3 on a LAMP stack)
      • 40706
      • 128 Posts
      I just had an email post Hook used in an Project.

      $placeholders = $fields['register.profile']->toArray();
      $placeholders['user.'] = $fields['register.user']->toArray();
      $placeholders += (array)$fields['register.profile']->get('extended');
      
      $modx->getService('mail', 'mail.modPHPMailer');
      $modx->mail->set(modMail::MAIL_BODY, $modx->getChunk('MailRegisterDe', $placeholders));
      $modx->mail->set(modMail::MAIL_FROM, $modx->getOption('emailsender'));
      $modx->mail->set(modMail::MAIL_FROM_NAME,'Registration Form');
      $modx->mail->set(modMail::MAIL_SUBJECT,'Check out new User!');
      $modx->mail->address('to','[email protected]');
      $modx->mail->setHTML(true);
      if (!$modx->mail->send()) {
          $modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$modx->mail->mailer->ErrorInfo);
      }
      $modx->mail->reset();
      return true;