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=np67233eb0b3c6d

Body

This is a MIME encoded message.

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

This is the text/plain version.

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

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

--np67233eb0b3c6d--

<?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);
 
?>