I have written a php script that will send emails to all the members belonging to the groups to which i want to receive the email . Now in this case it is obvious that a user can belong to multiple groups , what i want is that the such user shall receive only one email . Now the problem is that my script process one group at a time means it will first take one group determine details like fullname & email id for every user of that group & ultimately send mails to them . Then it will take the next group & repeat the same process . The code section that is doing the mentioned process is as follows :
------------------------------------------------------------------------------------------------------------
Code: Select all
for($i=0;$i<count($dest_group);$i++)
{
$sel_grp=$dest_group[$i];
$resultset=$modx->db->query("select tb1.fullname,tb1.email from modx_web_user_attributes tb1,modx_webgroup_names tb2,modx_web_groups tb3 where tb2.name='".$sel_grp."'and tb3.webgroup=tb2.id and tb1.id=tb3.webuser");
$grpusers=$modx->db->makeArray($resultset);
foreach($grpusers as $user)
$mail->AddAddress($user['email'],$user['fullname']);
$mail->Subject=$this->subject;
$mail->Body=$this->message;
if(!($mail->Send()))
$senderror[$i]=1;
} there are three database tables used in this code
(1) modx_web_user_attributes This table contains user's id , fullname & email id columns
(2)modx_webgroup_names This table contains group id & group name columns
(3)modx_web_groups This table contains userid & groupid to which this user belongs to
Any kind of help is really appreciable
Regards
Khuzema Dharwala