diff --git a/administrator/components/com_users/models/mail.php b/administrator/components/com_users/models/mail.php index 8f9ffc8a5b034..f5704c8e5840f 100644 --- a/administrator/components/com_users/models/mail.php +++ b/administrator/components/com_users/models/mail.php @@ -109,37 +109,38 @@ public function send() return false; } - // Get users in the group out of the ACL - $to = $access->getUsersByGroup($grp, $recurse); + // Get users in the group out of the ACL, if group is provided. + $to = $grp !== 0 ? $access->getUsersByGroup($grp, $recurse) : array(); - // Get all users email and group except for senders - $query = $db->getQuery(true) - ->select('email') - ->from('#__users') - ->where('id != ' . (int) $user->get('id')); - - if ($grp !== 0) + // When group is provided but no users are found in the group. + if ($grp !== 0 && !$to) { - if (empty($to)) + $rows = array(); + } + else + { + // Get all users email and group except for senders + $query = $db->getQuery(true) + ->select($db->quoteName('email')) + ->from($db->quoteName('#__users')) + ->where($db->quoteName('id') . ' != ' . (int) $user->id); + + if ($grp !== 0) { - $query->where('0'); + $query->where($db->quoteName('id') . ' IN (' . implode(',', $to) . ')'); } - else + + if ($disabled === 0) { - $query->where('id IN (' . implode(',', $to) . ')'); + $query->where($db->quoteName('block') . ' = 0'); } - } - if ($disabled == 0) - { - $query->where('block = 0'); + $db->setQuery($query); + $rows = $db->loadColumn(); } - $db->setQuery($query); - $rows = $db->loadColumn(); - // Check to see if there are any users in this group before we continue - if (!count($rows)) + if (!$rows) { $app->setUserState('com_users.display.mail.data', $data);