function encode_mime($data) { $array = utf8_str_split($data); $start = "=?UTF-8?B?"; $end = "?="; while(sizeof($array)) { $text = ''; while (strlen(base64_encode($text)) < 63 && sizeof($array)) { $text .= array_shift($array); } $new .= $start . base64_encode($text) . $end . ' '; } return substr($new, 0, -1); }