Mail_Mime::headers() – ヘッダ行を構築する


require_once 'Mail/mime.php';

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


電子メールの先頭に必要なヘッダ (MIME-Version と Content-Type) の配列を返します。 headers() を呼ぶ前に、関数get() を呼ばなければならないことに注意してください。


  • array $headerEx - 追加のヘッダで、引き数の書式は $array["header-name"] = "header-value" です。

  • boolean $overwrite - 既存のヘッダを上書きするかどうか。 FALSE の場合は既存の値をそのまま保持します。

Return value

array - MIME ヘッダおよび追加のヘッダの連想配列。 返り値は直接Mail::send() の第 2 パラメータに渡すことが出来ます。


This function can not be called statically.


メッセージを構築する (Previous) HTML 部分を設定する (Next)
Last updated: Tue, 24 Nov 2015 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report or add a note.
View this page in:

User Notes:

Note by:
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:

$headers['Subject'] = "Your Order Information";

Not this:
$headers['Subject'] = "Your Order Information\r\n";
Note by:
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.