Hey,
Does anyone know the script to send PMs?
I basically writing an own plugin where people can subscribe to, when a new notification is made, the user should be notified about it by PM.
Anyone know how to perform this?
Thanks in advance!
Tankey
require_once MYBB_ROOT."inc/datahandlers/pm.php";
$pmhandler = new PMDataHandler();
$pm = array(
"subject" => htmlspecialchars_uni("PM Title."),
"message" => htmlspecialchars_uni("Sample message."),
"icon" => -1,
"fromid" => 0,
"do" => '',
"pmid" => ''
);
$pm['toid'] = $uids_to_send_pm_to;
$pm['options'] = array(
"signature" => 0,
"disablesmilies" => 0,
"savecopy" => 0,
"readreceipt" => 0
);
$pm['saveasdraft'] = 0;
$pmhandler->admin_override = 1;
$pmhandler->set_data($pm);
if($pmhandler->validate_pm())
{
$pmhandler->insert_pm();
}
else
{
return false;
}
return true;
$uids_to_send_pm_to can be a list of uids to whom you wish to send PMs to.
You should be using htmlspecialchars_uni only when showing the title/message to the end user, not while inserting the PM to the DB (the datahandler already escapes this too), the following should work.
// We are ready to send it.
require_once MYBB_ROOT.'inc/datahandlers/pm.php';
$pmhandler = new PMDataHandler;
$pmhandler->admin_override = true; // if you want Flood checking, useless if the PM is send automatically
$pmhandler->set_data(array(
'subject' => 'Hello!', // the PM title
'message' => 'Hi!', // The message
'icon' => -1, // the icon
'fromid' => (int)$mybb->user['uid'], // UID who is sending the PM, MyBB Engine = -1
'toid' => array(1, 345) // users to send the PM to
));
if($pmhandler->validate_pm()) // insert if PM is valid
{
$pmhandler->insert_pm();
return true;
}
return false;
Whoaah nice!!
Ur post is idiot proof, thanks for the comments behind the lines!
I'm sure I'll get it working now, thx again