Login postHook not working

I’m trying to setup a postHook for my Register snippet with Login like mentioned here. I copied the exact example and changed just the email addresses, but it doesn’t work. My log only says An error occurred while trying to send the email: but nothing more.

Register Snippet
    &activationEmailSubject=`Registration pending`
hookRegisterEmail 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_FROM_NAME,'Site Name');
$modx->mail->set(modMail::MAIL_SENDER,'Site Name');
$modx->mail->set(modMail::MAIL_SUBJECT,'New User Signed Up');
if (!$modx->mail->send()) {
    $modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$err);
/* tell our snippet we're good and can continue */
return true;

MODX 2.7.3
mail is setup with SMTP through the system settings

What am I missing here?

That often means a problem with the email address of the sender. It usually needs to be an address has a mail account with your ISP.

Also, some people have been able to fix email problems by switching to SMTP (see the SMTP System Settings).

It is an email from the same ISP and also using your ActivationEmail Plugin, which works fine.


It that’s the case, using the QuickEmail extra with the same values might tell you what’s wrong. If QuickEmail works, it tells you that there’s something wrong with your code. If it doesn’t work, there’s a chance that you’ll get some diagnostic info.

So QuickEmail works fine, I get the email without any errors. I suspect the hook code to be wrong somewhere at this point, but I’m not sure how to test that and where to start. I compared it to your docs (“Using The MODX Mailer to send email”) but it looks fine to me.

Other than that, I found this error, not sure if that’s related , though:

[...]core/xpdo/om/xpdoobject.class.php : 240) Error 42000 executing statement: 
    [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` = 12' at line 1

Is there an option to get more error details from the hookRegisterEmail Snippet? Because the code should append the error, but all I get in the manager is:

[...]core/cache/includes/elements/modsnippet/50.include.cache.php : 15) An error occurred while trying to send the email: 

So there’s no actual error message there.

That’s why I hate email issues. It’s almost impossible to get enough information to diagnose things. If QuickEmail is sending from the same address with the same server, it’s hard to know what’s wrong. I’ve actually never used FormIt, so I can’t be much help there, but look for fields that the sender might want that are left out (QuickEmail in debug mode will show you everything it’s sending).

It might be possible to see something if you open Dev. Tools (F12) and watch the network tab while it’s processing the email. You can click on an individual line and drill down to see processor calls and responses.