E从Outlook到PHP的邮件

I am having trouble storing data with emails coming from OUTLOOK. I am using a pipe script to store data from incoming emails into an SQL Table but the issue is that if the email is coming from OUTLOOK, it is separated by ; instead of , So the email addresses in the 'TO' or 'CC' field are not stored in the table, only the first addressee gets stored. It works normally with all other emails. How do I tackle this issue ? Here is the code I am using:

#!/usr/bin/php-cli -c /home/abc/
<?php
    // Config
$dbuser = 'abc_user';
$dbpass = '1234';
$dbname = 'abc_testing';
$dbhost = 'localhost';
$notify= 'abc@def.com'; // an email address required in case of errors
function mailRead($iKlimit = "") 
{ 
if ($iKlimit == "") { 
$iKlimit = 1024; 
} 

// Error strings 
$sErrorSTDINFail = "Error - failed to read mail from STDIN!"; 

// Attempt to connect to STDIN 
$fp = fopen("php://stdin", "r"); 
// Failed to connect to STDIN? (shouldn't really happen) 
if (!$fp) { 
        echo $sErrorSTDINFail; 
        exit(); 
    } 

    // Create empty string for storing message 
    $sEmail = ""; 

    // Read message up until limit (if any) 
    if ($iKlimit == -1) { 
        while (!feof($fp)) { 
            $sEmail .= fread($fp, 1024); 
        }                     
    } else { 
        while (!feof($fp) && $i_limit < $iKlimit) { 
            $sEmail .= fread($fp, 1024); 
            $i_limit++; 
        }         
    } 

    // Close connection to STDIN 
    fclose($fp); 

    // Return message 
    return $sEmail; 
}  
$email = mailRead();

// handle email
$lines = explode("
", $email);

// empty vars
$from = "";
$subject = "";
$headers = "";
$message = "";
$splittingheaders = true;

for ($i=0; $i < count($lines); $i++) {
if ($splittingheaders) {
    // this is a header
    $headers .= $lines[$i]."
";

    // look out for special headers
    if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) {
        $subject = $matches[1];
    }
    if (preg_match("/^From: (.*)/", $lines[$i], $matches)) {
        $from = $matches[1];
    }
    if (preg_match("/^To: (.*)/", $lines[$i], $matches)) {
        $to = $matches[1];
    }
   } else {
    // not a header, but message
    $message .= $lines[$i]."
";
   }

   if (trim($lines[$i])=="") {
    // empty line, header section has ended
    $splittingheaders = false;
    }
   }

if ($conn = @mysql_connect($dbhost,$dbuser,$dbpass)) {
if(!@mysql_select_db($dbname,$conn))
mail($email,'Email Logger Error',"There was an error selecting the email logger          database.

".mysql_error());
 $from    = mysql_real_escape_string($from);
 $to    = mysql_real_escape_string($to);
 $subject = mysql_real_escape_string($subject);
 $headers = mysql_real_escape_string($headers);
 $message = mysql_real_escape_string($message);
 $email   = mysql_real_escape_string($email);
 $result = @mysql_query("INSERT INTO emails (`FROM`,`SUBJECT`,`TO`,`CC`) VALUES('$from','$subject','$to','$headers')");
 if (mysql_affected_rows() == 0)
mail($notify,'Email Logger Error',"There was an error inserting into the email logger database.

".mysql_error());
} else {
 mail($notify,'Email Logger Error',"There was an error connecting the email logger database.

".mysql_error());
  }

?>