MyBB Community Forums

Full Version: Custom php file send a private message?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
In this case, try the following;

<?php
define('IN_MYBB', 1); 
require "../../global.php"; 
$subject = "Test Subject";
$message = "Test Message";
$fromid = "1";
$toid = "1";
function ass()
{
   global $db, $mybb;

   if ($contact)
   {
        require_once MYBB_ROOT."inc/datahandlers/pm.php";
        $pmhandler = new PMDataHandler();

        $pm = array(
            "subject" => $subject,
            "message" => $message,
            "fromid" => $fromid,
            "toid" => $toid
        );

        $pm['options'] = array(
            "signature" => $mybb->input['pm_options']['signature'],
            "disablesmilies" => $mybb->input['pm_options']['disablesmilies'],
            "savecopy" => $mybb->input['pm_options']['savecopy'],
            "readreceipt" => $mybb->input['pm_options']['readreceipt']
        );

        $pmhandler->set_data($pm);

        // Now let the pm handler do all the hard work.
        if(!$pmhandler->validate_pm())
        {
            $pm_errors = $pmhandler->get_friendly_errors();
                        $pminfo = $pmhandler->insert_pm(); 
        }
}
return $contact;
}
?>
This still hasn't worked =[
nice topic, it was a handy topic for me, with a little change it works

The toid i've changed to an array of to with the username of the person. Also a fix in the last if statment, now you get an error or the pm replay as return value

If you want more persons, add an element in the array.
<?php

error_reporting(E_ALL);
ini_set('display_errors', 'On');

define('IN_MYBB', 1);
require "../forum/global.php";

function ass() {
	global $db, $mybb;
	$subject = "Final subject";
	$message = "Final Message";
	$fromid = "1";//still sender ID
	$to = array("Username1", "Username2"); // array of username(s)

	require_once MYBB_ROOT . "inc/datahandlers/pm.php";
	$pmhandler = new PMDataHandler();

	$pm = array(
		"subject" => $subject,
		"message" => $message,
		"fromid" => $fromid,
		"to" => $to
	);
	  
	$pm['options'] = array(
		"signature" => $mybb->input['pm_options']['signature'],
		"disablesmilies" => $mybb->input['pm_options']['disablesmilies'],
		"savecopy" => $mybb->input['pm_options']['savecopy'],
		"readreceipt" => $mybb->input['pm_options']['readreceipt']
	);

	$pmhandler->set_data($pm);

	// Now let the pm handler do all the hard work.
	if (!$pmhandler->validate_pm()) {
		$pm_errors = $pmhandler->get_friendly_errors();
		return $pm_errors;
	}else{
		$pminfo = $pmhandler->insert_pm();
		return $pminfo;
	}
}
debug(ass());

function debug($str) {
	echo "<pre>";
	var_dump($str);
	echo "</pre>";
}

?>

Pages: 1 2