You are here

function simplenews_mail_send in Simplenews 5

Mail engine to send newsletter. If you want to send HTML newsletters you need to plug in an extra module

Parameters

$mail: An object with at least $mail->to, $mail->subject, and $mail->message.

3 calls to simplenews_mail_send()
simplenews_mail_confirm in ./simplenews.module
Send confirmation email
simplenews_send_test in ./simplenews.module
Send a test newsletter
_simplenews_send in ./simplenews.module
Send the newsletter

File

./simplenews.module, line 1337

Code

function simplenews_mail_send($mail) {
  $from_email = isset($mail->from_address) ? $mail->from_address : variable_get('site_mail', ini_get('sendmail_from'));
  $from = isset($mail->from_name) ? '"' . mime_header_encode($mail->from_name) . '" <' . $from_email . '>' : $from_email;
  $headers = array(
    'From' => $from,
    'Reply-To' => $from_email,
    'X-Mailer' => 'Drupal',
    'Return-Path' => $from_email,
    'Errors-To' => $from_email,
  );

  // If receipt is requested, add headers.
  if ($mail->receipt) {
    $headers['Disposition-Notification-To'] = $from_email;
    $headers['X-Confirm-Reading-To'] = $from_email;
  }

  // Add priority if set.
  switch ($mail->priority) {
    case 1:
      $headers['Priority'] = 'High';
      $headers['X-Priority'] = '1';
      $headers['X-MSMail-Priority'] = 'Highest';
      break;
    case 2:
      $headers['Priority'] = 'urgent';
      $headers['X-Priority'] = '2';
      $headers['X-MSMail-Priority'] = 'High';
      break;
    case 3:
      $headers['Priority'] = 'normal';
      $headers['X-Priority'] = '3';
      $headers['X-MSMail-Priority'] = 'Normal';
      break;
    case 4:
      $headers['Priority'] = 'non-urgent';
      $headers['X-Priority'] = '4';
      $headers['X-MSMail-Priority'] = 'Low';
      break;
    case 5:
      $headers['Priority'] = 'non-urgent';
      $headers['X-Priority'] = '5';
      $headers['X-MSMail-Priority'] = 'Lowest';
      break;
  }

  // If subject is not set, default to title.
  if (!isset($mail->subject)) {
    $mail->subject = $mail->title;
  }
  if (module_exists('mimemail')) {
    if ($mail->s_format == 'plain') {
      $plain_text_only = TRUE;
      $plain_text_body = $mail->body;
    }
    else {
      $plain_text_only = FALSE;
      $plain_text_body = NULL;
    }
    if (variable_get('simplenews_debug', FALSE)) {
      watchdog('simplenews', t('Outgoing email via mimemail.<br />Subject: %subject<br />Recipient: %to', array(
        '%to' => $mail->to,
        '%subject' => $mail->subject,
      )), WATCHDOG_NOTICE);
    }
    return mimemail($from, $mail->to, $mail->subject, $mail->body, $plain_text_only, $headers, $plain_text_body, array(), 'simplenews-send-mail');
  }
  else {
    if (variable_get('simplenews_debug', FALSE)) {
      watchdog('simplenews', t('Outgoing email.<br />Subject: %subject<br />Recipient: %to', array(
        '%to' => $mail->to,
        '%subject' => $mail->subject,
      )), WATCHDOG_NOTICE);
    }
    return drupal_mail('simplenews-send-mail', $mail->to, $mail->subject, $mail->body, $from_email, $headers);
  }
}