You are here

function pm_email_notify_send_mail in Privatemsg 7.2

Same name and namespace in other branches
  1. 6.2 pm_email_notify/pm_email_notify.module \pm_email_notify_send_mail()

Send a pm notification email to a recipient.

2 calls to pm_email_notify_send_mail()
pm_email_notify_privatemsg_message_insert in pm_email_notify/pm_email_notify.module
Implements hook_privatemsg_message_insert().
pm_email_notify_privatemsg_message_recipient_changed in pm_email_notify/pm_email_notify.module
Implements hook_privatemsg_message_recipient_changed().

File

pm_email_notify/pm_email_notify.module, line 219
Notifies users about new Private Messages via Email.

Code

function pm_email_notify_send_mail($recipient, $message) {

  // Check if the recipient enabled email notifications.
  if (isset($recipient->uid) && !empty($recipient->mail) && _pm_email_notify_send_check($recipient->uid, $message)) {

    // Send them a new pm notification email if they did.
    $params['recipient'] = $recipient;
    $params['message'] = $message;
    if (_pm_email_notify_show_sender($message->author->uid)) {

      // User author's email as a sender.
      $from = $message->author->mail;
    }
    else {

      // Token replacements for email from address.
      $data = array(
        'privatemsg_message' => $params['message'],
        'privatemsg_recipient' => $params['recipient'],
      );
      $options = array(
        'language' => user_preferred_language($params['recipient']),
        // Don't sanitize output since this is used in an email, not a browser.
        'sanitize' => FALSE,
        // Custom token to avoid custom token handling.
        'privatemsg-display-invalid' => FALSE,
      );
      $from = trim(token_replace(variable_get('pm_email_notify_from', ''), $data, $options));
    }
    drupal_mail('pm_email_notify', 'notice', $recipient->mail, user_preferred_language($recipient), $params, !empty($from) ? $from : NULL);
  }
}