Hello,
I'm making a script (well want to). Which is a contact form that sends the information to my private message box.
But the one thing i am stuck on (which happens to be the most important feature) is sending the private message.
Anyone got any help for me?
I'm not looking for a straight up script i want the function to send a private message and i will build the script.
This is the default structure of PM sending in MyBB;
require_once MYBB_ROOT."inc/datahandlers/pm.php";
$pmhandler = new PMDataHandler();
$pm = array(
"subject" => $mybb->input['pm_subject'],
"message" => $mybb->input['pm_message'],
"fromid" => $mybb->user['uid'],
"toid" => array($user['uid'])
);
$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();
Sweet cheers buddy
How would i call this?
I have only just started php so i may seem dumb
You'd put this in a function or something and then call the function...
Ok and i would call it like this
functionname();
correct?
If you are using this in a "Plugin" then you have to make it as a hook, something like this;
$plugins->add_hook("index_start", "FUNCTION_NAME");
then you have to assign a "function" to that hook, something like below;
function FUNCTION_NAME()
{
global $db, $mybb;
// then your code or the above PM code goes on these lines
}
You just have to take care that your FUNCTION_NAME should be "same" with the plugin add hook variable and your function.
(2010-12-04, 12:39 PM)Yaldaram Wrote: [ -> ]If you are using this in a "Plugin" then you have to make it as a hook, something like this;
$plugins->add_hook("index_start", "FUNCTION_NAME");
then you have to assign a "function" to that hook, something like below;
function FUNCTION_NAME()
{
global $db, $mybb;
// then your code or the above PM code goes on these lines
}
You just have to take care that your FUNCTION_NAME should be "same" with the plugin add hook variable and your function.
It's not a plugin plugin, it is a custom php file in the forums folder called contact.php
I get this error
Parse error: syntax error, unexpected $end in /contact.php on line 33
<?php
define('IN_MYBB', 1);
require "../../global.php";
function ass()
{
global $db, $mybb;
require_once MYBB_ROOT."inc/datahandlers/pm.php";
$pmhandler = new PMDataHandler();
$pm = array(
"subject" => $mybb->input['pm_subject'],
"message" => $mybb->input['pm_message'],
"fromid" => $mybb->user['uid'],
"toid" => array($user['uid'])
);
$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();
}
ass();
?>
Yes this file is 2 directorys above the forums home (
www.site.com/forum/folder1/folder2/contact.php)
Any idea what the problem is?
This will not send PMs unless you call something to initiate this. e.g. If you want to send PMs "after" the User post all details in contact form then you have to use like this;
<?php
define('IN_MYBB', 1);
require "../../global.php";
function ass()
{
global $db, $mybb;
if ($contact)
{
require_once MYBB_ROOT."inc/datahandlers/pm.php";
$pmhandler = new PMDataHandler();
$pm = array(
"subject" => $mybb->input['pm_subject'],
"message" => $mybb->input['pm_message'],
"fromid" => $mybb->user['uid'],
"toid" => array($user['uid'])
);
$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;
?>
Still getting an error
Parse error: syntax error, unexpected $end in contact.php on line 41
<?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;
?>
You've not closed the { after if ($contact), it needs an } before the final } in the current code.