I was curious and then remembered I've got a web app that I use to mass email web logs. I found the guts of this function out on the 'net:
function BuildAttachment($file)
{
set_magic_quotes_runtime(0);
$fd = fopen($file, "rb");
$FileContent = fread($fd, filesize($file));
fclose($fd);
$FileContent = chunk_split(base64_encode($FileContent));
$attachment = $FileContent;
$attachment .="\n\n";
set_magic_quotes_runtime(get_magic_quotes_gpc());
return $attachment;
} // end function BuildAttachment($filename)
For what you need, I think it'll work something like this:
function BuildAttachment($string)
{
set_magic_quotes_runtime(0);
$FileContent = chunk_split(base64_encode($string));
$attachment = $FileContent;
$attachment .="\n\n";
set_magic_quotes_runtime(get_magic_quotes_gpc());
return $attachment;
} // end function BuildAttachment($string)
This 2nd function ditches the file handling and excepts a string and mime encodes it.
The attachment string then gets included here:
--MIME_BOUNDRY
Content-Type: <!--$contenttype$-->; name="<!--$filename$-->"
Content-disposition: attachment
Content-Transfer-Encoding: base64
<!--$attachment$-->
--MIME_BOUNDRY--
(Swap out my tokens for the actual data.)
This is all assuming you're working with a mime encoded message.