You are here

function answers_notify in Answers 6

Same name and namespace in other branches
  1. 5.2 answers.module \answers_notify()
  2. 7.3 includes/answers.notify.inc \answers_notify()
1 call to answers_notify()
_answers_notify_nodeapi in includes/answers.notify.inc

File

includes/answers.notify.inc, line 95
Notification functions for the 'Answers' module

Code

function answers_notify($nid) {
  global $user;
  $question = node_load($nid);
  $notify_p = $question->field_notify_p[0]['value'];

  // extract the nid of the question
  if ($notify_p) {
    $question_user = user_load($question->uid);
    $params = array(
      '!question_user_name' => $question_user->name,
      '!answer_user_name' => $user->uid == 0 ? 'anonymous' : $user->name,
      '!question_title' => $question->title,
      '!question_url' => url('node/' . $nid, array(
        'absolute' => TRUE,
        'target' => '_blank',
      )),
      '!site' => variable_get('site_name', 'drupal'),
    );
    $subject_template = variable_get('answers_answer_notification_subject', '');
    $subject = t($subject_template, $params);
    $body_template = variable_get('answers_answer_notification_body', '');
    $body = t($body_template, $params);
    $headers['Mime-Version'] = '1.0';
    $headers['Content-Type'] = "text/html";
    $message = array(
      'headers' => $headers,
      'to' => $question_user->mail,
      'from' => variable_get('site_mail', ini_get('sendmail_from')),
      'subject' => $subject,
      'body' => $body,
    );
    drupal_mail_send($message);
  }
}