You are here

public static function HTMLMailMime::toHeaders in HTML Mail 8

Same name and namespace in other branches
  1. 8.3 src/Utility/HtmlMailMime.php \Drupal\htmlmail\Utility\HtmlMailMime::toHeaders()

Returns an array with keys changed to match the case of email headers.

Parameters

string|array $input: The headers to be changed, either as a MAIL_MIME_CRLF-delimited string or as an associative array of (name => value) pairs.

Return value

array An associative array of (name => value) pairs, with the case changed to match normal email headers.

2 calls to HTMLMailMime::toHeaders()
HTMLMailMime::encodeEmail in src/Utility/HTMLMailMime.php
Convert message headers and body into an encoded string.
HTMLMailMime::toEmail in src/Utility/HTMLMailMime.php
Return a (headers, body) pair for sending.

File

src/Utility/HTMLMailMime.php, line 595
Provides the MailMIME class for creating MIME-formatted email messages.

Class

HTMLMailMime
Class HTMLMailMime.

Namespace

Drupal\htmlmail\Utility

Code

public static function toHeaders($input) {
  $headers = [];
  if (!is_array($input)) {
    $decoder = new \Mail_mimeDecode($input);
    $input = $decoder
      ->decode([
      'decode_headers' => TRUE,
      'input' => $input,
    ]);
  }
  foreach ($input as $name => $value) {
    $name = preg_replace([
      '/([[:alpha:]])([[:alpha:]]+)/',
      '/^Mime-/',
      '/-Id$/',
    ], [
      'strtoupper("\\1") . strtolower("\\2")',
      'MIME-',
      '-ID',
    ], $name);
    $headers[$name] = $value;
  }
  return $headers;
}