WHMCS Guru Support Forums

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Hooks Admin login notification (via email)

WHMCS Hooks

whmcsguru

Chief Guru
Staff member
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

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");
?>
 

Users who are viewing this thread

Back
Top