I think it could be much simpler in Revolution. I don't think you need anything more than something like this (untested):
function sendEmail($subject, $message) {
$headers ="MIME-Version: 1.0\n".
"Content-type: text/html; charset=iso-8859-1\n".
"From: ".$_SERVER['SERVER_NAME']."<no-reply@{$_SERVER['HTTP_HOST']}>\n".
"X-Mailer: PHP/".phpversion();
$body = $message
$mail = mail('[email protected]', $subject, $body, $headers);
}
switch ($modx->event->name) {
case 'OnManagerLogin':
$subject = 'Manager User Login';
break;
case 'OnWebLogin':
$subject = 'Web User Login';
break;
}
$username = $user->get('username');
$profile = $user->getOne('Profile');
$email = $profile->get('email');
$message = $username . ' has logged in on ' . date('l jS \of F Y h:i:s A');
sendEmail($subject, $message);
Note that the email function should go at the top, and I would test the function in a snippet, where debugging will be much easier, before putting it in the plugin.
BTW, if a lot of users are logging in, I would be tempted to create a log file (like the error log) and a snippet to display it (with a button to clear the log) rather than getting a whole bunch of emails. You could also very easily log the information to the existing Manager Actions log with $modx->logManagerAction(). If you do it right, that will record the time, username, and type of login. You can see it in Reports -> Manager Actions and can search and filter the report as well as clearing it.
[ed. note: BobRay last edited this post 13 years ago.]