We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1778
    • 659 Posts
    Hi all
    I'm using, Login.Register and it works fine except the post hook to send email info to admin when a new user is registered.

    To sure I used the code from http://rtfm.modx.com/display/ADDON/Login.Using+Pre+and+Post+Hooks and just change the "$modx->mail->address('to','[email protected]');" to fit my email address.

    Error log returns me the message "an error occured while trying to send the email"... But emails are well sent to new user.. I can't find why they are not to the admin....

    BTW I've set the system_setting "mail_use_smtp" to "Yes" and provide the good host in "mail_smtp_hosts" setting (once again it works fine for the email activation sent to new registered users)

    Any help would be appreciated
    Cheers

    INSTALLATION :
    Revolution 2.2.0-rc3 from git
    WAMP server install on Windows7
    PHP 5.3.8
    MySQL server: 5.5.16-log
    MySQL Client : mysqlnd 5.0.8-dev - 20102224 - $Revision: 310735 $

    Login version : 1.7.1 pl
    • This isfimiliar except that I didn't even get to see any error in the system log. My register call include this line: &postHooks=`postHook.DiscussLogin,hookNewUserRegToEmail` . I editted the emails asap.

      I don't know what might be wrong. The postHook.DiscussLogin is a hook from Disscuss extra. Since the FormIT tags are similar to LogIn tags, I presumed hooks in LogIn extra are separated by a comma.
      • Later realized something was missing: PHP open tag (<?php)
        So now I got error messages in the system log. This is the error:
        "
        [2013-05-05 13:41:53] (ERROR @ /index.php) [FormIt] Could not find hook "InputEmptyCheck".
        [2013-05-05 13:43:12] (ERROR @ /index.php) Could not get table class for class: modAccess
        [2013-05-05 13:43:12] (ERROR @ /index.php) Could not get table name for class: modAccess
        [2013-05-05 13:43:12] (ERROR @ /index.php) Error 42000 executing statement: 
        Array
        (
            [0] => 42000
            [1] => 1064
            [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS `modAccess` WHERE `modAccess`.`principal` = 20' at line 1
        )
        "

        So after a couple of tweaks, I decided to run a FormIT call on the Registration page. First the page just kept reloading without any action on data. Then I read this post (http://forums.modx.com/thread/?thread=44840) where BobRay you commented about adding an hidden submitVar to the form.

        Obeyed, still I got the same error above.

        My intension was to have the details submitted for registration be mailed to the admin as well as the regular acknowledgement to the user.
        [ed. note: ojchris last edited this post 10 years, 10 months ago.]
          • 3749
          • 24,544 Posts
          Do you have a snippet called "InputEmptyCheck" ?

          It might help to paste your FormIt tag here.
            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
          • With temporary solution I didn't bother. Now I'm able to test the code again On Login.Register snippet. No emails are sent and nor error in the log.

            The Register call:
            [[!Register?
            &submitVar=`registerbtn`
            &activationResourceId=`37`
            &activationEmailTpl=`ActivationEmailTpl`
            &activationEmailSubject=`Please activate your account`
            &submittedResourceId=`36`
            &usergroups=`Registered Vendors`
            &postHooks=`VendorRegistrationAlert`
            ]]


            and here is the code to send mail to admin (I have replaced the real emails used to counter spam):
            $message = 'Hi, a new Vendor 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,'[email protected]');
            $modx->mail->set(modMail::MAIL_FROM_NAME,'CPG Site');
            $modx->mail->set(modMail::MAIL_SENDER,'CPG Webmaster');
            $modx->mail->set(modMail::MAIL_SUBJECT,'New User Signed Up');
            $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: '.$err);
            }
            $modx->mail->reset();
            /* tell our snippet we're good and can continue */
            return true;
            


            What might be wrong?
            • I can answer myself: the activationResource was wrongly call. I had [[ConfirmRegister]] when it should be [[!ConfirmRegister]].

              So now the admin get's emailed but the user does not get the activation Email. There is a ModAcess error each time the form is filled. This is it:

              [2013-07-31 00:47:20] (ERROR @ /links/security/user.php) Could not get table class for class: modAccess
              [2013-07-31 00:47:20] (ERROR @ /links/security/user.php) Could not get table name for class: modAccess
              [2013-07-31 00:47:20] (ERROR @ /links/security/user.php) Error 42000 executing statement: 
              Array
              (
                  [0] => 42000
                  [1] => 1064
                  [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS `modAccess` WHERE `modAccess`.`principal` = 5' at line 1
              )
              
              [2013-07-31 00:56:04] (ERROR @ /links/security/user.php) Could not get table class for class: modAccess
              [2013-07-31 00:56:04] (ERROR @ /links/security/user.php) Could not get table name for class: modAccess
              [2013-07-31 00:56:04] (ERROR @ /links/security/user.php) Error 42000 executing statement: 
              Array
              (
                  [0] => 42000
                  [1] => 1064
                  [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS `modAccess` WHERE `modAccess`.`principal` = 7' at line 1
              )
              
              [2013-07-31 00:57:32] (ERROR @ /links/security/user.php) Could not get table class for class: modAccess
              [2013-07-31 00:57:32] (ERROR @ /links/security/user.php) Could not get table name for class: modAccess
              [2013-07-31 00:57:32] (ERROR @ /links/security/user.php) Error 42000 executing statement: 
              Array
              (
                  [0] => 42000
                  [1] => 1064
                  [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS `modAccess` WHERE `modAccess`.`principal` = 6' at line 1
              )
              
              [2013-07-31 00:57:42] (ERROR @ /links/security/user.php) Could not get table class for class: modAccess
              [2013-07-31 00:57:42] (ERROR @ /links/security/user.php) Could not get table name for class: modAccess
              [2013-07-31 00:57:42] (ERROR @ /links/security/user.php) Error 42000 executing statement: 
              Array
              (
                  [0] => 42000
                  [1] => 1064
                  [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS `modAccess` WHERE `modAccess`.`principal` = 4' at line 1
              )
              
              [2013-07-31 01:06:43] (ERROR @ /links/security/user.php) Could not get table class for class: modAccess
              [2013-07-31 01:06:43] (ERROR @ /links/security/user.php) Could not get table name for class: modAccess
              [2013-07-31 01:06:43] (ERROR @ /links/security/user.php) Error 42000 executing statement: 
              Array
              (
                  [0] => 42000
                  [1] => 1064
                  [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS `modAccess` WHERE `modAccess`.`principal` = 8' at line 1
              )
              
              [2013-07-31 01:06:51] (ERROR @ /links/security/user.php) Could not get table class for class: modAccess
              [2013-07-31 01:06:51] (ERROR @ /links/security/user.php) Could not get table name for class: modAccess
              [2013-07-31 01:06:51] (ERROR @ /links/security/user.php) Error 42000 executing statement: 
              Array
              (
                  [0] => 42000
                  [1] => 1064
                  [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS `modAccess` WHERE `modAccess`.`principal` = 3' at line 1
              )
              • BobRay to the rescue again. I read from this comment (by bobray)
                While testing you're hitting the "back" button on the Thanks for Registering page, and going back to the Register page.
                on this post http://forums.modx.com/thread/?thread=77630&page=1 a possible solution.

                So I tried to use a different browser each time for testing and the user gets the activation and the admin also gets his/her share.

                Even using a new tab of the same browser might result in errors. It's interesting that the system behaves this way. I think it's security attempt. Thanks. Now I can proceed to the other part of the project.

                Without BobRay and Sottwell on Modx.com I guess many will not survive on this platform. You can't appreciate their experience enough.
                  • 3749
                  • 24,544 Posts
                  Thanks for the kind words. smiley

                    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
                    • 35756
                    • 166 Posts
                    Hello!

                    I'm having the same problem as mentioned above:

                    An email gets sent to the user that registers, but the postHook-Email to the admin doesn't get send.

                    This is the mailAdmin-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,'[email protected]');
                    $modx->mail->set(modMail::MAIL_FROM_NAME,'My Site');
                    $modx->mail->set(modMail::MAIL_SENDER,'My Site');
                    $modx->mail->set(modMail::MAIL_SUBJECT,'New User Signed Up');
                    $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: '.$err);
                    }
                    $modx->mail->reset();
                    /* tell our snippet we're good and can continue */
                    return true;


                    This is the Register-call:

                    [[!Register?
                    &submitVar=`registerbtn`
                    &activationResourceId=`226`
                    &activationEmailTpl=`mailRegistrierung`
                    &activationEmailSubject=`Thanks for registering!`
                    &submittedResourceId=`231`
                    &usergroups=`Subscriber`
                    &postHooks=`mailAdmin`
                    &validate=`nospam:blank,
                    username:required:minLength=^6^,
                    password:required:minLength=^6^,
                    password_confirm:password_confirm=^password^,
                    fullname:required,
                    email:required:email`
                    &placeholderPrefix=`reg.`
                    ]]

                    I tried it in different browsers as mentioned above.

                    But I don't understand this statement by ojchris:

                    I can answer myself: the activationResource was wrongly call. I had [[ConfirmRegister]] when it should be [[!ConfirmRegister]].

                    The registering user doesn't get an activation-link with the register-confirmation-mail. He only gets informed that he/she has registered, the registration will be checked.

                    Additionally I use the ActivationEmail-Package by Bobray (thanks for this one), so when the admin sets a user to "active" the user gets notified about the confirmation and activation of his/her account...(btw.: is it possible to send within the activation-mail to the user his username and password, so he/she gets these informations displayed in the mail?)

                    I tried to edit the mailAdmin-snippet, so an error has to occur by deleting the first "$"...this works, so the postHook gets "fired".

                    Any help is highly appreciated!
                      • 35756
                      • 166 Posts
                      ok...I went through the rtfm again and read this:

                      preHooks
                      A comma-separated list of 'hooks', or Snippets, that will be executed before the user is registered but after validation. Also can specify 'recaptcha' as a hook.

                      postHooks
                      A comma-separated list of 'hooks', or Snippets, that will be executed after the user is registered.

                      So I changed my Register-call to this:

                      [[!Register?
                      &submitVar=`registerbtn`
                      &activationResourceId=`226`
                      &activationEmailTpl=`mailRegistrierung`
                      &activationEmailSubject=`Thanks for registering!`
                      &submittedResourceId=`231`
                      &usergroups=`Subscriber`
                      &preHooks=`mailAdmin`
                      &validate=`nospam:blank,
                      username:required:minLength=^6^,
                      password:required:minLength=^6^,
                      password_confirm:password_confirm=^password^,
                      fullname:required,
                      email:required:email`
                      &placeholderPrefix=`reg.`
                      ]]

                      from "postHooks" to "preHooks", but still no mail to the admin.

                      What I realized too is that the [[!+reg.error.message]] is always empty although there are validation-errors which get stated for example by this

                      [[!+reg.error.fullname:notempty=`Bitte tragen Sie in das Feld "<b>Name</b>" Ihren Namen ein.
                      `]]

                      Btw...MODx 2.2.15 and Login 1.8.1-Package