Admin Login Notification for WHMCS

whmcsguru

Chief Guru
Staff member
Jan 11, 2018
23
1
3
45
#1
When anyone logs in via admin, one would think the admins should be notified, right? Here's how to do this.
Save the following 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 = "Your Admin User Here";
 $values["type"] = "system";
 $values["customsubject"] = $subject;
 $values["custommessage"] = $body;

 $results = localAPI($command,$values,$adminuser);
 }

 add_hook("AdminLogin",1,"hook_email_adminonlogin");
?>
 
Top Bottom