I’d be embarrassed to say how long this took me, but this plugin definitely works (linked to OnBeforeUserFormSave):
<?php
if ($mode == modSystemEvent::MODE_UPD) {
if ( ! $user->get('active') && $_POST['active'] ) {
$modx->logManagerAction('activate_user','modUser',$user->get('id'));
$email = $_POST['email'];
/* Code to Send email goes here */
}
}
Paste the code into the plugin so you don’t have to worry about typos.
The logManagerAction line is optional. It will put a line in the Manager Action log (Reports->Manager Actions) so you can confirm that the user was activated and exactly when.
The code, as is, does nothing except put the line in the log because there’s no code to send the email.
I strongly advise you to work on the code to send the email in a snippet, not a plugin. Plugins are notoriously hard to debug and a typo can make the user save hang (reload the page if that happens). Once it’s working, paste it into the plugin.
The code above will not send an email if you create a new activated user in the Manager (even if you take out the first if statement). It only executes when you update an existing user. If you’d like it to do that too, let me know.