PHP管道电子邮件 - 从Body Array获取数据行

The following works well for a structured email piped to the script. My problem is the bottom piece of the code where it goes through the body array. I am getting emails that are not structured where the first 15 characters are defined.

How change I change or modify the script below so that the emails body's first line is assigned to $fname, second line is assigned to $lname, and third line is assigned to $email?

$fd = fopen("php://stdin", "r");    
$data = "";   
while (!feof($fd)) {        
$data .= fread($fd, 1024);    
}    
fclose($fd);  

list($header, $body) = explode("

", $data, 2);

$body_array = explode("
", $body);
$header_array = explode("
", $header);

foreach ($header_array as $data_line) {
$first_six =  substr(trim($data_line), 0,6);

    switch ($first_six) {
        case  'From: ' :
            $from = $data_line;
            $from = str_replace('From: ', '',$from );
             break;

        default :
            $dummy = '';
    }
}


foreach ($body_array as $data_line) {
 $first_fifeteen =  substr(trim($data_line), 0,15);

    switch ($first_fifeteen) {
        case 'First Name    :' :
            $fname = $data_line;
            $fname = str_replace('First Name    : ', '',$fname )  ;
            break;

    case 'Last Name     :':
            $lname = $data_line;
            $lname = str_replace('Last Name     : ', '',$lname )  ;
            break;

        case 'Email         :':
            $email = $data_line;
            $email = str_replace('Email         : ', '',$email )  ;
    break;

        default :
            $dummy = '';
    }
}