Jump to content

Sending email on admin login


Stefany93

Recommended Posts

Howdy colleagues,


Please help! I am writing a WP plugin the boss of the website to be notified when an admin logs in. So far so good, but I can't make the damn code to send the email when the user logs in. If I change the add_action to "admin_notices" the email is being sent, but if I put "wp_login" it does not :( Please help, here is the code so far...



function _emnoti_get_time_of_login(){
$time_of_login = date('l F Y');
return $time_of_login;
}
# Get the IP of the user that logged themselves as admin

function _emnoti_get_ip(){
$sources = array(
'REMOTE_ADDR',
'HTTP_X_FORWARDED_FOR',
'HTTP_CLIENT_IP',
);
foreach ($sources as $source) {
if(!empty($_SERVER[$source])){
$ip = $_SERVER[$source];
}
}
return $ip;
}

# Email all the info above to a pointed email address
function emnoti_send_email($user_login, $user){
if(_emnoti_check_if_admin() === true){
// print _emnoti_get_time_of_login();
// print _emnoti_get_ip();
wp_mail("MY EMAIL!", "Test subject", 'test body');
}
}

add_action('wp_login', 'emnoti_send_email', 10, 2);

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.