You are here

function mimemail_headers in Mime Mail 6

Same name and namespace in other branches
  1. 5 mimemail.inc \mimemail_headers()
  2. 7 mimemail.inc \mimemail_headers()

Gives useful defaults for standard email headers.

Parameters

$headers: An array of headers.

Return value

An array containing the encoded headers with the default values.

1 call to mimemail_headers()
mimemail_prepare_message in ./mimemail.module
Default engine's prepare function.

File

./mimemail.inc, line 54
Common mail functions for sending e-mail. Originally written by Gerhard.

Code

function mimemail_headers($headers, $from = NULL) {
  $default_from = variable_get('site_mail', ini_get('sendmail_from'));

  // Overwrite standard headers.
  if ($from) {
    if (!isset($headers['From']) || $headers['From'] == $default_from) {
      $headers['From'] = $from;
    }
    if (!isset($headers['Sender']) || $headers['Sender'] == $default_from) {
      $headers['Sender'] = $from;
    }

    // This may not work. The MTA may rewrite the Return-Path.
    if (!isset($headers['Return-Path']) || $headers['Return-Path'] == $default_from) {
      preg_match('/[a-z\\d\\-\\.\\+_]+@(?:[a-z\\d\\-]+\\.)+[a-z\\d]{2,4}/i', $from, $matches);
      $headers['Return-Path'] = "<{$matches[0]}>";
    }
  }

  // Convert From header if it is an array.
  if (is_array($headers['From'])) {
    $headers['From'] = mimemail_address($headers['From']);
  }

  // Run all headers through mime_header_encode() to convert non-ascii
  // characters to an rfc compliant string, similar to drupal_mail().
  foreach ($headers as $key => $value) {
    $headers[$key] = mime_header_encode($value);
  }
  return $headers;
}