title: send PHP mail with Content-Type: multipart/alternative
body: <p>I am trying to send a multipart mail that contains both html and plain text. This is also one of the ways to get through spam filters and to allow more people to read the mail in case of not supporting HTML. After spending long hours googling, I have found some examples. I made my code, which sends the mail but it displays the text with the html tags, code, string etc. </p>
  
  <pre><code>&lt;?php
  $boundary=md5(uniqid(rand()));
  $header .= "From:My Name&lt;something@something.com&gt;\n";
  $header .= "Reply-To: something@something.com \n";
  $header .= 'MIME-Version: 1.0'."\r\n";
  $header .= 'Content-type: multipart/alternative;boundary=$boundary '."\n";
  
  $adres = "something@gmail.com";
  
  $subject = "subject";
  
  $message = "This is multipart message using MIME\n";
  $message .= "--" . $boundary . "\n";
  $message .= "Content-type: text/plain;charset=iso-8859-1\n";
  $message .= "Content-Transfer-Encoding: 7bit". "\n\n";
  $message .= "Plain text version\n\n";
  $message .="--" . $boundary . "\n";
  $message .="Content-type: text/html;charset=iso-8859-1\n";
  $message .= "Content-Transfer-Encoding: 7bit". "\n\n";
  $message .="&lt;html&gt;
  &lt;body&gt;
  &lt;center&gt;
  &lt;b&gt;HTML text version&lt;/b&gt;
  &lt;/center&gt;
  &lt;/body&gt;
  &lt;/html&gt;\n\n";
  $message .= "--" . $boundary . "--";
  
  if(mail($adres, $subject, $message, $header))
  {
  print'message sent';
  }
  else
  {
  print'message was not sent';
  }
  ?&gt;
  </code></pre>
  
  <p>This is the result:</p>
  
  <pre><code>    This is multipart message using MIME
      --c071adfa945491cac7759a760ff8baeb
      Content-type: text/plain;charset=iso-8859-1
      Content-Transfer-Encoding: 7bit
  
      Plain text version
  
      --c071adfa945491cac7759a760ff8baeb
      Content-type: text/html;charset=iso-8859-1
      Content-Transfer-Encoding: 7bit
  
      &lt;html&gt;
      &lt;body&gt;
      &lt;center&gt;
      &lt;b&gt;HTML text version&lt;/b&gt;
      &lt;/center&gt;
      &lt;/body&gt;
      &lt;/html&gt;
  
      --c071adfa945491cac7759a760ff8baeb--
  </code></pre>
  
  <p>As you can see it displays the coding instead of the message alone. I have tried many solutions posted like: </p>
  
  <ul>
  <li>adding/removing \r\n;</li>
  <li>changing \r\n to \n;</li>
  <li>changing content type from alternative to mixed;</li>
  </ul>
  
  <p>I am learning PHP and all I know is all I have read and done so far. I have still much to learn so please if you could tell me where is the problem. I would be very thankful.Best regards.</p>