Sending multipart/alternative e-mails; text/plain and text/html

According to RFC 1341 and http://www.freesoft.org/CIE/RFC/1521/18.htm:

Headers

MIME-Version: 1.0
From: Foo <foo@bar.com>
Subject: Test mail
Content-Type: multipart/alternative;boundary=np6621c60a3a86f

Body

This is a MIME encoded message.

--np6621c60a3a86f
Content-type: text/plain;charset=utf-8

This is the text/plain version.

--np6621c60a3a86f
Content-type: text/html;charset=utf-8

This is the <b>text/html</b> version.

--np6621c60a3a86f--

<?php

 $boundary = uniqid('np');
 
 
 $headers = "MIME-Version: 1.0\r\n";
 $headers .= "From: Foo <foo@bar.com>\r\n";
 $headers .= "Subject: Test mail\r\n";
 $headers .= "Content-Type: multipart/alternative;boundary=" . $boundary . "\r\n";

 
 $message = "This is a MIME encoded message."; 
 
 $message .= "\r\n\r\n--" . $boundary . "\r\n";
 $message .= "Content-type: text/plain;charset=utf-8\r\n\r\n";
 $message .= "This is the text/plain version.";

 $message .= "\r\n\r\n--" . $boundary . "\r\n";
 $message .= "Content-type: text/html;charset=utf-8\r\n\r\n";
 $message .= "This is the <b>text/html</b> version.";

 $message .= "\r\n\r\n--" . $boundary . "--";
 
 //mail('bar@foo.com', 'Test mail', $message, $headers);
 
?>