function _node_registration_send_email in Node registration 7
Internal send e-mail function.
3 calls to _node_registration_send_email()
- node_registration_cancel_action in includes/
node_registration.actions.inc - Action handler: cancel registration.
- node_registration_form_submit in includes/
node_registration.forms.inc - Submit handler for node_registration_form().
- node_registration_send_broadcast in includes/
node_registration.api.inc - Send an email to all registrations for a given node.
File
- includes/
node_registration.api.inc, line 257 - Registration API functions.
Code
function _node_registration_send_email($recipient, $subject, $message, $token_data = array(), $options = array()) {
$recipient_account = user_load_by_mail($recipient);
$language = $recipient_account ? user_preferred_language($recipient_account) : language_default();
// Set up from. Fill in later.
$from_name = '';
$from_email = '';
// Auto complete token objects.
if (isset($token_data['node-registration'])) {
if (!empty($token_data['node-registration']->author_uid) && empty($token_data['node-registration']->author)) {
$token_data['node-registration']->author = user_load($token_data['node-registration']->author_uid);
}
if (!empty($token_data['node-registration']->uid) && empty($token_data['node-registration']->user)) {
$token_data['node-registration']->user = user_load($token_data['node-registration']->uid);
}
if (!empty($token_data['node-registration']->node) && empty($token_data['node'])) {
$token_data['node'] = $token_data['node-registration']->node;
}
}
// From name + e-mail.
if (isset($token_data['from'])) {
$from_name = $token_data['from']['from_name'];
$from_email = $token_data['from']['from_email'];
}
elseif (isset($token_data['node'])) {
$settings = $token_data['node']->registration;
$settings->sender_name && ($from_name = token_replace($settings->sender_name, $token_data, array(
'clear' => TRUE,
)));
$settings->sender_mail && ($from_email = token_replace($settings->sender_mail, $token_data, array(
'clear' => TRUE,
)));
}
// Add defaults and combine.
$from_name or $from_name = _node_registration_default_from_name();
$from_email or $from_email = variable_get('site_mail');
$from = $from_name . ' <' . $from_email . '>';
// Translate subject & message.
$subject = t($subject, array(), array(
'context' => 'node_registration',
'langcode' => $language->language,
));
$message = t($message, array(), array(
'context' => 'node_registration',
'langcode' => $language->language,
));
// Token data.
if ($token_data) {
$subject = token_replace($subject, $token_data, array(
'clear' => TRUE,
'language' => $language,
));
$message = token_replace($message, $token_data, array(
'clear' => TRUE,
'language' => $language,
));
}
// Mail params.
$params = array(
'subject' => $subject,
'message' => $message,
) + $options;
$type = isset($options['alter']) ? $options['alter'] : 'broadcast';
$result = drupal_mail('node_registration', $type, $recipient, $language, $params, $from);
return $result['result'];
}