Using PHP to send a pm.
#21
(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?
Please don't PM me for support. Smile
Reply
#22
This user has been denied support. This user has been denied support.
(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
Reply
#23
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)
Reply
#24
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?
Reply
#25
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.
Do not ask me help through PM or Discord
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)