Mail_Mime::headers()

Mail_Mime::headers() – build the header lines

Synopsis

require_once 'Mail/mime.php';

array &headers ( array $xtra_headers = null , boolean $overwrite = false , boolean $skip_content = false )

Description

Returns an array with the headers needed to prepend to the email (MIME-Version and Content-Type). Please note that the function get() has to be called before calling headers().

Parameter

  • array $xtra_headers - Additional headers, the format of the argument is $array["header-name"] = "header-value"

  • boolean $overwrite - Overwrite already existing headers. When FALSE, the values already set are kept.

  • boolean $skip_content Don't return content headers: Content-Type, Content-Disposition and Content-Transfer-Encoding.

Return value

array - an associative array with the mime headers and the additional headers. The return value can directly passed to the second parameter of Mail::send().

Note

This function can not be called statically.

Mail_Mime::headers() has to be called after Mail_Mime::get().

build the message (Previous) set HTML part (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

Note by: jasmo@varikas.fi
At least in my case, setting Content-Type headers first and then passing headers to headers() allowing it overwrite old headers does not work properly.

$mime->headers($headers, true);

It just didn't overwrite the content-type header, but added other one.

If you are having problems that Outlook does not show mime-content right but other programs work, be sure that you don't set Content-Type headers before passing headers to headers()
Note by: NWdev
It appears Mail_mime adds the \r\n to the individual headers via the _encodeHeaders function (mime.php in version 1.5.2) -- so you can avoid spinning your wheels by not adding them again to your header values:

This:
<code>
$headers['Subject'] = "Your Order Information";
</code>

Not this:
<code>
$headers['Subject'] = "Your Order Information\r\n";
</code>
Note by: dcasper@pressaprint.com
I ran into this so others may as well. When attempting to assign a custom Content-Type header to your messages you need to remember to call the function as

$mime->headers($hdrs, true);

In order to get your custom header to get used. There's a default Content-Type header of text/plain that only gets replaced if you pass along the $overwrite boolean as true.
Note by: Stephen Dewey
Note that although this page omits it, you should still add the To field explicitly using this function.