You can use PHPMailer ( https://github.com/PHPMailer/PHPMailer/ ) with imap.
<?php
// after creating content of mail you have to run preSend() - part of send() method
$mail->send();
// and you can get whole raw message with getSentMIMEMessage() method
imap_append($imap, $mailserver.'INBOX.Sent',$mail->getSentMIMEMessage(), "\\Seen");