function messaging_message_send in Messaging 5
Same name and namespace in other branches
- 6.4 messaging.module \messaging_message_send()
- 6 messaging.module \messaging_message_send()
- 6.2 messaging.module \messaging_message_send()
- 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 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)
5 calls to messaging_message_send()
- Messaging_API_Tests::testMessagingBasicAPI in tests/
messaging_api.test - Play with creating, retrieving, deleting a pair messages
- messaging_debug_send_user in messaging_debug/
messaging_debug.module - Just show message title to the user.
- 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
- messaging_sms_send_user in messaging_sms/
messaging_sms.module - Send mail message to user account
File
- ./
messaging.module, line 454
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);
// Provides a hook for other modules to modify the message before sending
foreach (module_implements('message_alter') as $module) {
$function = $module . '_message_alter';
$function($message, $info, $method);
}
// Renders subject and body applying filters in the process
if (!empty($info['render'])) {
$message = call_user_func($info['render'], $message, $info);
}
else {
$message = messaging_message_render($message, $info);
}
// Decide on queue, log, cron and send options, prepara parameters
$sent = $cron = $log = 0;
// If the messaging method is of type push, cron processing will be enabled
if ($queue && $info['type'] & MESSAGING_TYPE_PUSH) {
$cron = 1;
}
// It will be queued always for pull methods
if ($queue || $info['type'] & MESSAGING_TYPE_PULL) {
$queue = 1;
}
// And it will be kept as log if logging or debug enabled
if (variable_get('messaging_log', 0)) {
$log = 1;
}
// Send if not for queueing or not debugging enabled
if (variable_get('messaging_debug', 0) && function_exists('messaging_debug_send_msg')) {
$log = 1;
$cron = 0;
$method = 'debug';
}
if (!$queue) {
$success = TRUE;
foreach ($destinations as $to) {
// Be careful with the order of function && value, so they both are evaluated
$success = messaging_message_send_out($to, $message, $method) && $success;
}
// If sent, set time. If failed force logging.
$success ? $sent = time() : ($log = 1);
}
// Depending on parameters and what's happened so far we make the final queue/log decision
if ($queue || $log) {
messaging_store('save', $method, $destinations, $message, $sent, $queue, $log, $cron);
$sent = TRUE;
}
// This will return true if the message was sent or queued for delivery
return $sent || $queue;
}