您的位置:首页 > 编程语言 > PHP开发

php mailparse 解析 .eml 文件

2014-07-28 16:06 543 查看
foreach ($filname as $k => $v) {
$suffix = explode('.', $v);
switch ($suffix[1]) {
case 'eml':
$mime = mailparse_msg_parse_file($this->save_path.'/'.$v);    //mime 解析文件
$struct = mailparse_msg_get_structure($mime);   //解析 结构
foreach ($struct as $k => $st) {
$section = mailparse_msg_get_part($mime, $st);   //解析 根据 id 获取part
$info = mailparse_msg_get_part_data($section);   // 获取 part 数据信息 array()

if ($info['content-type'] == 'application/octet-stream' && $info['content-disposition'] == 'attachment') {
$name = iconv('gbk', 'utf-8', $info['content-name']);
$name_array = explode('.', $name);
if (is_array($name_array)) {
$name = urlencode($name_array[0]);
ob_start();   // 打开缓冲区
mailparse_msg_extract_part_file($section, $this->save_path.'/'.$v);   // 读取 制动part 内的数据
$contents = ob_get_contents();   //获取数据

ob_end_clean();
$file_hanle = fopen($this->save_path . '/' . $name . '.' . $name_array[1], 'w+');
fwrite($file_hanle, $contents);
fclose($file_hanle);
}
}
}
//unlink($v);
}
}
使用扩展 mailparse 注意安装
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: