Send an email to a selected group

scorpia2009

New member
Hi to all,
I am trying to figure out how to send an email to a selected group of users.
I have a form that enables some users to create tasks. There is an option available to select the group the task is intended for.
However, i cant figure out how to correctly write the hook, after inserting a new task, to send an email to the users that are in the selected goups.
Of course all data regarding the emails are stored in the users table.
Many Thanks in advance!!!
 

darren

Member
using the template for the hook provided

[pre]
$hooks['accounts']['insert']['after'] = 'dadabik_send_notice_after_accounts_insert';

function dadabik_send_notice_after_accounts_insert($id_account)
{
global $conn;

// get the ID of the group
$sql = "SELECT email_accounts FROM dadabik_users WHERE id_group = :id_group";

$res_prepare = prepare_db($conn, $sql);

$res_bind = bind_param_db($res_prepare, ':id_group', $id_group);

$res = execute_prepared_db($res_prepare,0);

$row = fetch_row_db($res_prepare)

mail ('john@mysite.com', 'New account inserted', 'A new account ('.$row['name_account'].') has been added.');

}
[/pre]

then you replace the

[pre]
mail ('john@mysite.com', 'New account inserted', 'A new account ('.$row['name_account'].') has been added.');
[/pre]

with something like:

[pre]
foreach ($row as $value) {

mail ("$value", 'SUBJECT', 'MESSAGE');

}
[/pre]

I wrote this very much on the fly and I dont use MySQL anymore, so there are bound to be some errors, also this assumes that you want to mail to the group of the person who submitted the insert. If the group will always be the same then replace :id_group with the actual number of the id_group
 
Top