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

时间:2015-04-02 15:18:38

标签: php email

以下适用于通过管道传输到脚本的结构化电子邮件。我的问题是它通过body数组的底部代码。我收到的电子邮件的结构不是前15个字符的定义。

我如何更改或修改下面的脚本,以便将电子邮件正文的第一行分配给$ fname,将第二行分配给$ lname,将第三行分配给$ email?

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

list($header, $body) = explode("\n\n", $data, 2);

$body_array = explode("\n", $body);
$header_array = explode("\n", $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 = '';
    }
}

0 个答案:

没有答案