You are here

public function EmailMerge::emailDocs in Forena Reports 7.5

1 call to EmailMerge::emailDocs()
EmailMerge::render in src/DocumentFormats/EmailMerge.php

File

src/DocumentFormats/EmailMerge.php, line 89
EmailMerge.inc email merge document. @author davidmetzler

Class

EmailMerge

Namespace

Drupal\forena\DocumentFormats

Code

public function emailDocs($docs, $test_mode = NULL, $max = 10, $subject = '', $body = '') {
  global $user;
  $test_send = $test_mode !== NULL ? $test_mode : variable_get('forena_email_override', FALSE);
  print "test send: {$test_send}";
  $i = 0;
  $sent = 0;
  if ($body) {
    $body = check_markup($body, variable_get('forena_email_input_format', filter_default_format()));
  }
  print_r($docs, 'doc');
  foreach ($docs as $doc) {
    $to = $test_send ? $user->mail : $doc['to'];
    $from = $doc['from'];

    // Replace body
    if ($body) {
      $doc['parms']['body'] = $body;
    }

    // Replace subject
    if ($subject) {
      $doc['parms']['subject'] = $subject;
    }
    if ($test_send) {
      $i++;

      // Remove bcc and cc
      unset($doc['parms']['headers']);
    }
    if ($i <= $max) {
      $sent++;
      drupal_mail('forena', 'mailmerge', $to, language_default(), $doc['parms'], $from, TRUE);
    }
  }
  drupal_set_message(t('Sent %count messages ', array(
    '%count' => $sent,
  )));
}