Where to begin? I have a very successful newsletter script for PHP-Fusion 7.02.xx CMS system. Currently it will send to single or multiple users w/attachments; also will send to a user group w/attachments. I have a need/request from a user to add multiple user group capability. Well sending to 1 user group is no problem. User groups are stored in the 'users' table like this: Say a user belongs to 3 user groups, 1 3 and 4. the 'user_groups' field for his record in the db looks like this:
.1.3.4
Below is the usergroup select code and the email addies extraction code according to usergroup, that as I said currently works fine:
// Select user group
echo "<table cellspacing='0' cellpadding='0' border='0'><tr>\n";
echo "<td valign='middle' align='left' width='300'><input type='radio' name='delivery' value='grp'".$grp."> ".$locale['nl_447']."</td>\n";
echo "<td align='center'>\n";
echo "<select name='sendto' size='6' class='textbox' style='width:140px;'>";
$result = dbquery("SELECT * FROM ".DB_USER_GROUPS."");
if (dbrows($result) != 0) {
while ($data = dbarray($result)) {
$selected = (isset($_GET['group_id']) && $_GET['group_id'] == $data['group_id']) ? 'selected="selected"' : '';
echo "<option value='".$data['group_id']."'$selected>".$data['group_name']."</option>\n";
}
}
echo "</select>\n";
echo "</td>\n</tr></table><br /><br /></td>\n";
echo "</tr><tr>\n";
// End select user group
// Get usergroup and email addresses
$subject = stripslashes($_POST['subject']);
$frommail = $settings['siteemail'];
$usrtxt = stripslashes($_POST['msg']);
$format = $_POST['format'];
$grID = $_POST['sendto'];
$result = dbquery("SELECT user_email FROM ".DB_USERS." WHERE user_newsletter='1' AND user_groups REGEXP('^\\\,{$grID}$|\\\,{$grID}\\\,|\\\,{$grID}$')");
if (dbrows($result)) {
$rows = dbrows($result);
while ($data = dbarray($result)) {
$addies = $data['user_email'].',';
$my_array = explode(",",$addies);
foreach($my_array AS $dudes) {
$prep = $dudes;
$array[] = $prep;
$list = implode(",",$array);
$to_mail = $list;
$list_array = explode(",",$to_mail);
}
}
}
reset($list_array);
// End get usergroup
I think I will still have to use REGEX to send to multiple usergroups but have no idea how to go about it. Any help would be appreciated.