diff --git a/smtp.mail.inc b/smtp.mail.inc
index b220eeb..e469a8b 100644
--- a/smtp.mail.inc
+++ b/smtp.mail.inc
@@ -98,13 +98,10 @@ class SmtpMailSystem implements MailSystemInterface {
         }
       }
     }
-    if (preg_match('/^"?.*"?\s*<.*>$/', $from)) {
-      // . == Matches any single character except line break characters \r and \n.
-      // * == Repeats the previous item zero or more times.
-      $from_name = preg_replace('/"?([^("\t\n)]*)"?.*$/', '$1', $from); // It gives: Name
-      $from      = preg_replace("/(.*)\<(.*)\>/i", '$2', $from); // It gives: name@domain.tld
-    }
-    elseif (!valid_email_address($from)) {
+
+    $from_comp = $this->_get_components($from);
+
+    if (!valid_email_address($from_comp['addr'])) {
       drupal_set_message(t('The submitted from address (@from) is not valid.', array('@from' => $from)), 'error');
       watchdog('smtp', 'The submitted from address (@from) is not valid.', array('@from' => $from), WATCHDOG_ERROR);
       return FALSE;
@@ -112,23 +109,15 @@ class SmtpMailSystem implements MailSystemInterface {
 
     // Defines the From value to what we expect.
     $mailer->From     = $from;
-    $mailer->FromName = $from_name;
-    $mailer->Sender   = $from;
+    $mailer->FromName = $from_comp['name'];
+    $mailer->Sender   = $from_comp['addr'];
 
 
     // Create the list of 'To:' recipients.
     $torecipients = explode(',', $to);
     foreach ($torecipients as $torecipient) {
-      if (strpos($torecipient, '<') !== FALSE) {
-        $toparts = explode(' <', $torecipient);
-        $toname = $toparts[0];
-        $toaddr = rtrim($toparts[1], '>');
-      }
-      else {
-        $toname = '';
-        $toaddr = $torecipient;
-      }
-      $mailer->AddAddress($toaddr, $toname);
+      $to_comp = $this->_get_components($torecipient);
+      $mailer->AddAddress($to_comp['addr'], $to_comp['name']);
     }
 
 
@@ -212,16 +201,8 @@ class SmtpMailSystem implements MailSystemInterface {
         case 'reply-to':
           // Only add a "reply-to" if it's not the same as "return-path".
           if ($value != $headers['Return-Path']) {
-            if (strpos($value, '<') !== FALSE) {
-              $replyToParts = explode('<', $value);
-              $replyToName = trim($replyToParts[0]);
-              $replyToName = trim($replyToName, '"');
-              $replyToAddr = rtrim($replyToParts[1], '>');
-              $mailer->AddReplyTo($replyToAddr, $replyToName);
-            }
-            else {
-              $mailer->AddReplyTo($value);
-            }
+            $replyto_comp = $this->_get_components($value);
+            $mailer->AddReplyTo($replyto_comp['addr'], $replyto_comp['name']);
           }
           break;
 
@@ -230,14 +211,8 @@ class SmtpMailSystem implements MailSystemInterface {
           break;
 
         case 'return-path':
-          if (strpos($value, '<') !== FALSE) {
-            $returnPathParts = explode('<', $value);
-            $returnPathAddr = rtrim($returnPathParts[1], '>');
-            $mailer->Sender = $returnPathAddr;
-          }
-          else {
-            $mailer->Sender = $value;
-          }
+          $returnpath_comp = $this->_get_components($value);
+          $mailer->Sender = $returnpath_comp['addr'];
           break;
 
         case 'mime-version':
@@ -252,32 +227,16 @@ class SmtpMailSystem implements MailSystemInterface {
         case 'cc':
           $ccrecipients = explode(',', $value);
           foreach ($ccrecipients as $ccrecipient) {
-            if (strpos($ccrecipient, '<') !== FALSE) {
-              $ccparts = explode(' <', $ccrecipient);
-              $ccname = $ccparts[0];
-              $ccaddr = rtrim($ccparts[1], '>');
-            }
-            else {
-              $ccname = '';
-              $ccaddr = $ccrecipient;
-            }
-            $mailer->AddCC($ccaddr, $ccname);
+            $cc_comp = $this->_get_components($ccrecipient);
+            $mailer->AddCC($cc_comp['addr'], $cc_comp['name']);
           }
           break;
 
         case 'bcc':
           $bccrecipients = explode(',', $value);
           foreach ($bccrecipients as $bccrecipient) {
-            if (strpos($bccrecipient, '<') !== FALSE) {
-              $bccparts = explode(' <', $bccrecipient);
-              $bccname = $bccparts[0];
-              $bccaddr = rtrim($bccparts[1], '>');
-            }
-            else {
-              $bccname = '';
-              $bccaddr = $bccrecipient;
-            }
-            $mailer->AddBCC($bccaddr, $bccname);
+            $bcc_comp = $this->_get_components($bccrecipient);
+            $mailer->AddBCC($bcc_comp['addr'], $bcc_comp['name']);
           }
           break;
 
@@ -630,4 +589,27 @@ class SmtpMailSystem implements MailSystemInterface {
 
     return $substring;
   }  //  End of _smtp_get_substring().
+
+  protected function _get_components($name_and_address) {
+    // Check if the provided $name_and_address already has the one of the following formats and split them up.
+    // - some name <address@example.com>
+    // - "another name" <address@example.com>
+    // - <address@example.com>
+    $comp = array(
+      'name' => '',
+      'addr' => '',
+    );
+
+    // If the provided string is already a valid email address, then return that.
+    if (valid_email_address($name_and_address)) {
+      $comp['addr'] = $name_and_address;
+      return $comp;
+    }
+
+    if (preg_match('/^"?([^"\t\n]*)"?\s*<([^>\t\n]*)>$/', $name_and_address, $matches)) {
+      $comp['name'] = trim($matches[1]);
+      $comp['addr'] = trim($matches[2]);
+    }
+    return $comp;
+  }  //  End of _smtp_get_components().
 }
