It's definitely possible. You could take any PHP mailer class that can handle attachments, and rewrite the addAttachment function where it reads data from file to accept your variable instead.
Zend_Mail seems to be able to digest strings as attachments directly, without any rewriting.