This older hook still works today. I updated this a few years back for v6, still works now.
This hook will notify your admin user that someone logged in to their account.
Save this as a php file in includes/hooks
This hook will notify your admin user that someone logged in to their account.
Save this as a php file in includes/hooks
PHP:
<?php
/* admin login notification for WHMCS
retooled for v6
04-20-2016 - UPdated to use Capsule
*/
use Illuminate\Database\Capsule\Manager as Capsule;
function hook_email_adminonlogin($vars)
{
$adminid = $vars['adminid'];
if (!filter_var($adminid, FILTER_VALIDATE_INT))
{
return;
}
$ip=$_SERVER['REMOTE_ADDR'];
$admininfo = Capsule::table('tbladmins') ->select('username') ->where('id', '=', $adminid)->get();
foreach ($admininfo as $adminrow)
{
$ausername = $adminrow->username;
}
$subject = "[WHMCS] Admin login notification";
$body = "WHMCS Admin Login Notification for " . $ausername . " from " . $ip;
/* calling the local api to do the job */
$command = "sendadminemail";
$adminuser = "youradminuser";
$values["type"] = "system";
$values["customsubject"] = $subject;
$values["custommessage"] = $body;
$results = localAPI($command,$values,$adminuser);
}
add_hook("AdminLogin",1,"hook_email_adminonlogin");
?>