We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 49311
    • 22 Posts
    Hello everyone,

    I am currently trying to get Login to send out an email to the website admin when a user registers. I followed the directions located here: http://rtfm.modx.com/extras/revo/login/login.tutorials/login.using-pre-and-post-hooks

    And come across people with similar issues here: https://forums.modx.com/thread/44858/register-custom-email-posthook-not-working

    It appears the issue was resolved with Login was updated. However, I am still unable to get it to work.

    Any help would be greatly appreciated.

    Thanks.

    - Mike

    Using:
    MODX Revolution 2.3.2-pl (traditional)
    Login 1.9.0-pl

    Register Call:
    [[!Register?
        &submitVar=`registerbtn`
        &activationResourceId=`98`
        &activationEmailTpl=`myActivationEmailTpl`
        &activationEmailSubject=`Thanks for Registering!`
        &submittedResourceId=`97`
        &usergroups=`Protected:Member`
        &validate=`nospam:blank,
        username:required:minLength=^6^,
        password:required:minLength=^6^,
        password_confirm:password_confirm=^password^,
        fullname:required,
        email:required:email`
        &placeholderPrefix=`reg.`
        &postHooks=`hookComEmail`
    ]]


    hookComEmail snippet:
    <?php
    $message = 'A new user has 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,'my email address');
    $modx->mail->set(modMail::MAIL_FROM_NAME,'Name would go here');
    $modx->mail->set(modMail::MAIL_SENDER,'Sender would go here');
    $modx->mail->set(modMail::MAIL_SUBJECT,'New User Signed Up');
    $modx->mail->address('to','my email address');
    $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;


    I checked the MODX error logs and did get this:

    [2015-01-29 10:35:16] (ERROR @ /connectors/index.php) Could not get table class for class: modAccess
    [2015-01-29 10:35:16] (ERROR @ /connectors/index.php) Could not get table name for class: modAccess
    [2015-01-29 10:35:16] (ERROR @ /connectors/index.php) Error 42000 executing statement: 
    Array
    (
        [0] => 42000
        [1] => 1038
        [2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Change the alias to a valid name.
    )
    
    [2015-01-29 10:35:50] (ERROR @ /index.php) An error occurred while trying to send the email: 
    [2015-01-29 10:38:12] (ERROR @ /connectors/index.php) Could not get table class for class: modAccess
    [2015-01-29 10:38:12] (ERROR @ /connectors/index.php) Could not get table name for class: modAccess
    [2015-01-29 10:38:12] (ERROR @ /connectors/index.php) Error 42000 executing statement: 
    Array
    (
        [0] => 42000
        [1] => 1038
        [2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Change the alias to a valid name.
    )
    
    [2015-01-29 10:39:51] (ERROR @ /index.php) An error occurred while trying to send the email: 

    This question has been answered by BobRay. See the first response.

    • discuss.answer
      • 3749
      • 24,544 Posts
      Are you sure the mail() function is enabled on the server? It often isn't. The QuickEmail extra will tell you.
        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
        • 49311
        • 22 Posts
        Thanks BobRay for the quick reply!

        I used your QuickEmail extra and everything checked out okay.

        When looking at your QuickEmail tutorial, I came across your MODX mailer code and tried using that instead of what was listed in the Login tutorials and that seemed to fix the issue.

        In comparing the two, the only difference appears to be what is listed after
        $modx->mail->setHTML(true);


        Login Tutorial:
        $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;


        Your code:
        $modx->mail->setHTML(true);
        $sent = $modx->mail->send();
        if ($sent) {
            $output = 'Mail Sent';
        } else {
            $output = 'Mail Not Sent';
        }
        return $output;


        Any idea what may have caused the issue between what Login provided and what you wrote?

        Thanks again for all the help you have always provided!

        - Mike
          • 3749
          • 24,544 Posts
          I think the only real difference is the $modx->mail->reset() line. TBH, I'm not sure what it does.
            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
            • 49311
            • 22 Posts
            Well, your method worked, so thanks again for the help.

            BobRay to the rescue once again.

            Much appreciated.

            - Mike
              • 42541
              • 18 Posts