MyBB Community Forums

Full Version: Send automatic PM
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

There are couple Plugin available that enable us to send automatic welcome PM to new member upon registration but that is not what I need.
I want to send an automatic PM from admin to a member when a function on my custom page gets executed.

For example, something like that:

<?php
define("IN_MYBB", 1);
require_once "../global.php";

$data = '';//some data
$result = $db->query('
SELECT * FROM '.TABLE_PREFIX.'test
WHERE `data` = "'.$db->escape_string($data).'"
LIMIT 1');

if($result == TRUE){
$db_r = mysqli_fetch_assoc($result);
if ($db_r['data'] == $data){
echo "Already exists";
exit();
} else {
$new_record = array(
"uid" => intval($mybb->user["uid"]),
"username" => $db->escape_string($mybb->user["username"]),
"data" => $db->escape_string($data)
);
$db->insert_query('test', $new_record);
//and send PM to the user that new record was successfully created.
}
?>

Is there any quick and easy method to accomplish this?


Regards
You can call the send_pm function.

inc/functions ~8005
/**
 * Send a Private Message to a user.
 *
 * @param array Array containing: 'subject', 'message', 'touid' and 'receivepms' (the latter should reflect the value found in the users table: receivepms and receivefrombuddy)
 * @param int Sender UID (0 if you want to use $mybb->user['uid'] or -1 to use MyBB Engine)
 * @param bool Whether or not do override user defined options for receiving PMs
 * @return bool True if PM sent
 */

function send_pm($pm, $fromid = 0, $admin_override=false)

Example:

send_pm(array('subject' => 'Yoursubject', 'Message' => 'Message', 'touid' => $userID, 'receivepms' => true), 1, true);