You are here

function og_email_form_submit in Organic groups 5.2

Same name and namespace in other branches
  1. 5 og.module \og_email_form_submit()
  2. 5.7 og.module \og_email_form_submit()

File

./og.module, line 313

Code

function og_email_form_submit($form_id, $form_values) {
  $node = node_load($form_values[gid]);
  $variables = array(
    '@group' => $node->title,
    '@body' => $form_values['body'],
    '@site' => variable_get('site_name', drupal),
    '!url_group' => url("node/{$node->nid}", NULL, NULL, TRUE),
    '!url_unsubscribe' => url("og/unsubscribe/{$node->nid}", NULL, NULL, TRUE),
  );
  global $user;
  $from = $user->mail;
  $sql = og_list_users_sql(1);
  $result = db_query($sql, $form_values['gid']);
  while ($row = db_fetch_object($result)) {
    $emails[] = $row->mail;
  }
  foreach ($emails as $mail) {
    drupal_mail('og_mail', trim($mail), $form_values['subject'], _og_user_mail_text('og_admin_email_body', $variables), $from);
  }
  drupal_set_message(format_plural(count($emails), '1 email sent.', '@count emails sent'));
  drupal_goto("node/{$form_values[gid]}");
}