Hi there..
Is there a way to send a privatemsg message with my own module? Is there a hook or something like that?

Comments

iterator’s picture

Anyone?

jeebsuk’s picture

In your own module, you need to get the user objects of both the sender and recipient.

There is a function called _privatemsg_send() it takes the following parameters:

_privatemsg_send($sender,$recipient,$subject,$message_body,$format,$thread);

$format I am not 100% sure on, but I have it set to 1 and that works fine.

To get the correct value for $thread I run the following:

$result = db_query('SELECT MAX(thread) as max_thread FROM {privatemsg});
while ($row = db_fetch_object($result) {
      $highest_thread_count = $row->max_thread;
}

//then add one to avoid your message becoming part of the wrong thread
$highest_thread_count = $highest_thread_count + 1;

That should help you out.

berdir’s picture

This is for D5.

For D6, use the following function: http://blog.worldempire.ch/de/api/function/privatemsg_new_thread/1

You can also reply to a existing thread, see http://blog.worldempire.ch/de/api/function/privatemsg_reply/1