Conditional Email for usergroup

emcguire

Member
I have a form that is sending to a particular usergroup, but I do not want to send the email to the owner of the submitted record. It is a notification email to the users in that group, but I don't need to notify the person that submitted the form(that person is in the same group I'm emailing).

If I put in a condition that returns false on the user that submits the form, will it globally not send the email to anyone or just that person? I'm not sure if the condition is global, meaning that if the condition is false, that it will not send ANY emails or only not send the email where the condition is false...
 
The condition is "all or nothing". If the condition returns false, the plugin just doesn't run.

I think the only way you could do that would be to build you own list of addresses using "Email to (eval)".

Probably something like this:

Code:
$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);
$myQuery
   ->select('u.email')
   ->from('#__users AS u')
   ->leftJoin('#__user_usergroup_map AS ug ON ug.user_id = u.id')
   ->where('ug.group_id = 123')
   ->where('ug.user_id != ' . JFactory::getUser()->get('id'));
$myDb->setQuery($myQuery);
$myEmails = $myDb->loadColumn('email');
return implode(',', $myEmails);

Replace 123 with your group ID.

-- hugh
 
Thanks Hugh!

I tried that with:


PHP:
$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);
$myQuery
   ->select('u.email')
   ->from('nab_users AS u')
   ->leftJoin('nab_user_usergroup_map AS ug ON ug.user_id = u.id')
   ->where('ug.group_id = 3')
   ->where('ug.user_id != ' . JFactory::getUser()->get('id'));
$myDb->setQuery($myQuery);
$myEmails = $myDb->loadColumn('email');
return implode(',', $myEmails);

It did not send any emails, This looks like it should work to me. I'm not getting any errors. When I dump it, it returns : array(1) { [0]=> NULL }

I am using the "author" usergroup as a test, there is 2 of us in that group, one of which being me.

I'm not an expert on the syntax, is there something we may be missing?
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top