Login plugin Hooks not running

408 views Asked by At

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 snippet 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`
]]
1

There are 1 answers

0
Vierkante Meter On

I've done something similar before. There is my code:

[[!Register? &postHooks=`sendMessageToAdmin`

Snippet sendMessageToAdmin:

 <?php
    $message = 'Auto message:<br><br>A new user signed up: '.$hook->getValue('fullname') . ', using email address '.$hook->getValue('email').'.';

    $modx->getService('mail', 'mail.modPHPMailer');
    $modx->mail->set(modMail::MAIL_BODY,$message);
    $modx->mail->set(modMail::MAIL_FROM,'[email protected]');
    $modx->mail->set(modMail::MAIL_FROM_NAME,'My website');
    $modx->mail->set(modMail::MAIL_SENDER,'Auto message from my website');
    $modx->mail->set(modMail::MAIL_SUBJECT,'Someone signed up');
    $modx->mail->address('to','[email protected]');
    $modx->mail->setHTML(true);
    if (!$modx->mail->send()) {
        $modx->log(modX::LOG_LEVEL_ERROR,'sendMessageToAdmin: An error occurred while trying to send the email: '.$err);
    }
    $modx->mail->reset();
    /* tell our snippet we're good and can continue */
    return true;