You are here

function messaging_message_send in Messaging 6

Same name and namespace in other branches
  1. 5 messaging.module \messaging_message_send()
  2. 6.4 messaging.module \messaging_message_send()
  3. 6.2 messaging.module \messaging_message_send()
  4. 6.3 messaging.module \messaging_message_send()

Send message to array of destinations. The message is rendered just once.

The $message array may have the following elements 'subject' => Message subject, may be already rendered or not 'body' => Message content, may be already rendered or not 'params' => Optional message params, indexed by sending method group I.e. params for mail methods will be in $message['params']['mail'] 'render' => Optional flag to mark the message subject and body as rendered 'sender' => Optional int to identify message sender, may be $user->uid 'sender_account' => Optional user account to use as message sender

Parameters

$destinations: Array of destinations for sending. The element type depends on sending method so it can be a list of e-mail addresses, user accounts, etc

$message: Message object or array, not rendered

$method: Sending method. Unlike for messaging_message_send_user() for which the sending method may be user's default it is not an optional parameter for this function.

$queue: Optional flag, 0 for normal queueing, 1 to force queueing. We may want to force queueing for bulk messaging. Otherwise it will depend on the sending method wether to queue the messages (for pull methods) or not (push methods)

4 calls to messaging_message_send()
Messaging_API_Tests::testMessagingSendingAPI in tests/messaging_api.test
Play with creating, retrieving, deleting a pair messages
messaging_debug_post_form_submit in messaging_debug/messaging_debug.module
Post test message
messaging_message_send_user in ./messaging.module
Send message to user represented by account
Messaging_Methods_Tests::testMessagingMethods in tests/messaging_methods.test
Test message sending callbacks for enabled plug-ins

File

./messaging.module, line 232

Code

function messaging_message_send($destinations, &$message, $method, $queue = 0) {

  // Get default sending method, or default for this user account
  $method = $method ? $method : messaging_method_default(NULL);
  $info = messaging_method_info($method, NULL, array());

  // Convert into an object and add all the information into the message object
  $message = (object) $message;
  $message->method = $method;
  $message->source['type'] = 'outgoing';
  $message->destinations = $destinations;
  $message->queue = $queue;
  $message->sent = $message->queued = 0;

  // Message preprocessing, before sending
  $message->process = TRUE;
  $message = messaging_message_callbacks(array(
    'prepare',
    'render',
    'presend',
  ), $message, $info);

  // If queue / send call the next hooks
  if ($message->process) {
    if ($message->queue) {
      $callbacks = array(
        'queue',
        'afterqueue',
      );
    }
    else {
      $callbacks = array(
        'multisend',
        'aftersend',
      );
    }
    $message = messaging_message_callbacks($callbacks, $message, $info);
  }

  // This will return true if the message was sent or queued for delivery
  if (!isset($message->success)) {
    $message->success = $message->sent || $message->queued;
  }
  return $message->success;
}