You are here

function messaging_privatemsg_send_msg in Messaging 6.4

Same name and namespace in other branches
  1. 6 messaging_privatemsg/messaging_privatemsg.module \messaging_privatemsg_send_msg()
  2. 6.2 messaging_privatemsg/messaging_privatemsg.module \messaging_privatemsg_send_msg()
  3. 6.3 messaging_privatemsg/messaging_privatemsg.module \messaging_privatemsg_send_msg()

Send mail message to user accounts

Privatemsg API documentation on http://drupal.org/node/369399 As we cannot use privatemsg_new_thread(), we bypass validation and send the message with the internal function _privatemsg_send()

See http://drupal.org/node/726874

Parameters

$destination: User account or user id

1 string reference to 'messaging_privatemsg_send_msg'
messaging_privatemsg_messaging in messaging_privatemsg/messaging_privatemsg.module
Implementation of hook_messaging

File

messaging_privatemsg/messaging_privatemsg.module, line 44
Simple mail using Drupal API. Messaging method plug-in

Code

function messaging_privatemsg_send_msg($destination, $message) {

  // Prepare the privatemsg parameters
  $recipient = messaging_user_object($destination);
  $author = $message
    ->get_sender();
  $privatemsg = array();
  $privatemsg['subject'] = $message
    ->get_subject();
  $privatemsg['body'] = $message
    ->get_body();
  $privatemsg['recipients'][$recipient->uid] = $recipient;

  // Apply defaults - this will not overwrite existing keys.
  $privatemsg += array(
    'author' => $author,
    'timestamp' => time(),
    'format' => filter_resolve_format(FILTER_FORMAT_DEFAULT),
  );

  // Send
  $privatemsg = _privatemsg_send($privatemsg);
  return !empty($privatemsg['mid']);
}