title: What are special characters in E-Mail-Headers and when to use quotes?
body: <p>I'm trying to send and read e-mail using PHP. So far I found out, that I have to encode special characters using the function <code>mb_encode_mimeheader()</code>, But I don't have to encode spaces.</p>
  <p>I also found out, that brackets in adress-filed don't work: (<a href="http://stackoverflow.com/questions/11989915/is-there-an-error-in-phps-imap-fetch-overview-function-when-reading-headers-w">Is there an error in PHP&#39;s imap_fetch_overview()-function when reading headers with brackets?</a>). For example PHP is unable to the header-section <code>From: Admin [] &lt;user@mail.tld&gt;</code>, but can read the header-section <code>From: &quot;Admin []&quot; &lt;user@mail.tld&gt;</code>.</p>
  <p>So, obviously brackets have a special meaning in the mail-header (at least for PHP). <strong>What are there for special characters in the Mailheader</strong>, <strong>what ist their meaning</strong>, and <strong>where do they need to be encoded/quoted?</strong></p>
  <p>For example, PHP has no problems with brackets in the subject, although the Subject is also Part of the header.</p>
  <p>It seems that quotes can help me with the problem (<a href="https://www.rfc-editor.org/rfc/rfc5322#section-3.2.4" rel="nofollow noreferrer">https://www.rfc-editor.org/rfc/rfc5322#section-3.2.4</a> - I'm still not 100% sure if this is a problem of PHP or an incorrect mailheader). <strong>But how to use quotes, and what is escaped by quotes?</strong></p>
  <p>In <a href="https://www.rfc-editor.org/rfc/rfc5322#section-3.2.4" rel="nofollow noreferrer">https://www.rfc-editor.org/rfc/rfc5322#section-3.2.4</a> it says:</p>
  <blockquote>
  <p>Strings of characters that include characters other than those
  allowed in atoms can be represented in a quoted string format, where
  the characters are surrounded by quote (DQUOTE, ASCII value 34)
  characters.</p>
  </blockquote>
  <p>So, should I now &quot;escape/quote&quot; each character on his own</p>
  <pre><code>From: Admin &quot;[&quot;&quot;]&quot; &lt;user@mail.tld&gt;
  </code></pre>
  <p>or is it fine to quote everything together?</p>
  <pre><code>From: &quot;Admin []&quot; &lt;user@mail.tld&gt;
  </code></pre>
  <p>But what happens, if other control sequences are enclosed withing the quotes? For example I have the special characters <code>ÄÖÜ</code> within my String, which are encoded to <code>=?UTF-8?B?w4PChMODwpbDg8Kc?=</code>. <strong>So, will 'quoted AND encoded' strings still be fine according to the RFC?</strong></p>
  <pre><code>From: &quot;Admin [=?UTF-8?B?w4PChMODwpbDg8Kc?=]&quot; &lt;user@mail.tld&gt;
  </code></pre>