diff --git a/mailmime.inc b/mailmime.inc
index e08a67a..110084c 100644
--- a/mailmime.inc
+++ b/mailmime.inc
@@ -779,14 +779,19 @@ class MailMIME extends Mail_mime {
       )->headers;
     }
     foreach ($input as $name => $value) {
+      $name = preg_replace_callback(
+          '/([[:alpha:]])([[:alpha:]]+)/',
+          function($matches) {
+            return strtoupper($matches[1]) . strtolower($matches[2]);
+          },
+        $name
+      );
       $name = preg_replace(
         array(
-          '/([[:alpha:]])([[:alpha:]]+)/e',
           '/^Mime-/',
           '/-Id$/',
         ),
         array(
-          'strtoupper("\1") . strtolower("\2")',
           'MIME-',
           '-ID',
         ),
