MyBB Community Forums

Full Version: Using PHP to send a pm.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
(2012-12-08, 05:53 AM)Omar G. Wrote: [ -> ]You will need to get the users (UIDs) from that group (GIDs).

I feel like I'm missing something horribly obvious, but how would I do that?
(2012-12-08, 08:12 AM)Seabody Wrote: [ -> ]
(2012-12-08, 05:53 AM)Omar G. Wrote: [ -> ]You will need to get the users (UIDs) from that group (GIDs).

I feel like I'm missing something horribly obvious, but how would I do that?
Short example:

//Fetch all users with usergroup, let's say 2, i.e. registered usergroup

$query = $db->query("SELECT * FROM ".TABLE_PREFIX."users WHERE `usergroup`= 2");

$uids_to_send_pm_to = array();
while($fetch = $db->fetch($query))
{
$uids_to_send_pm_to = $fetch['uid'];
}

//Now for $pm['toid'] field, you should use $uids_to_send_pm_to variable
That would be the basic and easiest code, yes. But we can be picky.
  • We only need the UIDS (not need to request much data).
  • We also want to get users which secondary groups match our group.

$sender = -1; // MyBB Engine
$gid = 2;
switch($db->type)
{
	case 'pgsql':
	case 'sqlite3':
	case 'sqlite2':
		$sql = '\',\'||additionalgroups||\',\'';
		break;
	default:
		$sql = 'CONCAT(\',\',additionalgroups,\',\')';
		break;
}
$query = $db->simple_select('users', 'uid', 'usergroup=\''.$gid.'\' OR '.$sql.' LIKE \'%,'.$gid.',%\'');

$uids = array();
while($uid = $db->fetch_field($query, 'uid'))
{
	$uids[(int)$uid] = 1;
}

sendPM('Hi!', 'This is a PM sent to you.', array_keys($uids), $sender)
Im trying to find similar... a Plugin that sends New Users a PM that can be edited by Afdmin... FYI I get an SQL error using the main "WELCOME PM Plugin" is there another plugin that can do this? or does anyone kno WHY its doing this?
You can try MyBot to automate a lot of things.

Concerning your error, turn on error logging to see what the real issue is.
ACP -> Configuration -> Server & Optimization settings -> Error logging/Error_logging_medium. Enable error logging and display.
Pages: 1 2 3