Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 电子邮件解码不';我不在zend mail工作_Php_Zend Framework_Zend Mail - Fatal编程技术网

Php 电子邮件解码不';我不在zend mail工作

Php 电子邮件解码不';我不在zend mail工作,php,zend-framework,zend-mail,Php,Zend Framework,Zend Mail,我有一个脚本,可以访问指定的电子邮件并获取邮件$temp->getContent()重复以下内容 ----boundary_2710_edfb8b44-71c8-49ff-a8cb-88c83382c4ee Content-Type: multipart/alternative; boundary=--boundary_2709_dde0dd0e-ba35-4469-949d-5392aec65750 --boundary_2709_dde0dd0e-ba35-4469-949d-5392a

我有一个脚本,可以访问指定的电子邮件并获取邮件
$temp->getContent()
重复以下内容

----boundary_2710_edfb8b44-71c8-49ff-a8cb-88c83382c4ee 
Content-Type: multipart/alternative; 
boundary=--boundary_2709_dde0dd0e-ba35-4469-949d-5392aec65750 --boundary_2709_dde0dd0e-ba35-4469-949d-5392aec65750 
Content-Type: text/html; charset=utf-8 
Content-Transfer-Encoding: base64 
PGZvcm0gbWV0aG9k.........this part is base64 encoded and it works fine if i copy and decode it separately.......AgICAgICAgICAgDQoNCjwvZm9ybT4= 
----boundary_2709_dde0dd0e-ba35-4469-949d-5392aec65750-- ----boundary_2710_edfb8b44-71c8-49ff-a8cb-88c83382c4ee 
Content-Type: multipart/mixed; boundary=--boundary_2711_eca4cfc3-fc62-43d6-b9fb-e5295abbfbe8 ----boundary_2711_eca4cfc3-fc62-43d6-b9fb-e5295abbfbe8 Content-Type: application/pdf; 
name=redBusTicket.pdf 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment Content-ID: JVBERi0xLjIgCiXi48/TIAoxIDAgb2JqIAo8PCAKL1R5cGUgL0NhdGFsb2cgCi9QYWdlcyAy IDAgUiAKL1BhZ2VNb2RlIC9Vc2VOb25lIAovVmlld2VyUHJlZ
在这些内容之间有base64编码部分,如果我单独复制和解码它,它就可以正常工作。邮件中还有一个附件。我怎样才能得到附件。下面是我的代码。当我直接使用base64_解码时,我没有得到任何输出。。只是一张空白页

$storage = new Zend_Mail_Storage_Imap($imap);
$temp = $storage->getMessage($_GET['mailid']);
echo base64_decode($temp->getContent());

zend网站中的文档不是很好。需要帮助

我有类似的东西可以从电子邮件中获取基本内容。试着过滤掉你不需要的东西

if ($email->isMultipart() && $partsCount){

    for($i = 1; $i < $email->countParts() +1; $i++) {
        $part = $email->getPart($i);
        $headers = $part->getHeaders();
        if (
            array_key_exists('content-description', $headers)
             || array_key_exists('content-disposition', $headers)

        ){
            if (array_key_exists('content-description', $headers)) {
                $att = $part->getContent();
                $filepath = utf8_encode(DATA_PATH . '/' . $part->getHeader('content-description'));
                if (is_file($filepath)) {
                    unlink($filepath); // deletes previous files with same name
                }
                $file = fopen($filepath, "w");
                fwrite($file, base64_decode($att));
                fclose($file);
                $attachments[] = $filepath;
            } 
        }

    }
}
if($email->isMultipart()&&&$partscont){
对于($i=1;$i<$email->countParts()+1;$i++){
$part=$email->getPart($i);
$headers=$part->getHeaders();
如果(
数组\密钥\存在('content-description',$headers)
||数组\键\存在('content-disposition',$headers)
){
如果(数组\键\存在('content-description',$headers)){
$att=$part->getContent();
$filepath=utf8_编码(数据_路径'/'.$part->getHeader('content-description'));
如果(是_文件($filepath)){
取消链接($filepath);//删除以前同名的文件
}
$file=fopen($filepath,“w”);
fwrite($file,base64_decode($att));
fclose($文件);
$attachments[]=$filepath;
} 
}
}
}

我有类似的方法从电子邮件中获取基本内容。试着过滤掉你不需要的东西

if ($email->isMultipart() && $partsCount){

    for($i = 1; $i < $email->countParts() +1; $i++) {
        $part = $email->getPart($i);
        $headers = $part->getHeaders();
        if (
            array_key_exists('content-description', $headers)
             || array_key_exists('content-disposition', $headers)

        ){
            if (array_key_exists('content-description', $headers)) {
                $att = $part->getContent();
                $filepath = utf8_encode(DATA_PATH . '/' . $part->getHeader('content-description'));
                if (is_file($filepath)) {
                    unlink($filepath); // deletes previous files with same name
                }
                $file = fopen($filepath, "w");
                fwrite($file, base64_decode($att));
                fclose($file);
                $attachments[] = $filepath;
            } 
        }

    }
}
if($email->isMultipart()&&&$partscont){
对于($i=1;$i<$email->countParts()+1;$i++){
$part=$email->getPart($i);
$headers=$part->getHeaders();
如果(
数组\密钥\存在('content-description',$headers)
||数组\键\存在('content-disposition',$headers)
){
如果(数组\键\存在('content-description',$headers)){
$att=$part->getContent();
$filepath=utf8_编码(数据_路径'/'.$part->getHeader('content-description'));
如果(是_文件($filepath)){
取消链接($filepath);//删除以前同名的文件
}
$file=fopen($filepath,“w”);
fwrite($file,base64_decode($att));
fclose($文件);
$attachments[]=$filepath;
} 
}
}
}
它对我很有用:

foreach ($mail as $message) {

    $content = null;      
    foreach (new RecursiveIteratorIterator($message) as $part) {
        if (strtok($part->contentType, ';') == 'text/plain') {
            $content = $part;
            break;
        }
    }

    if ($content) {
        echo "\n encode: " . $content->contentTransferEncoding;        
        echo "\n date: " . $message->date;
        echo "\n subject: \n" . iconv_mime_decode($message->subject, 0, 'UTF-8');
        echo "\n plain text part: \n" . mb_convert_encoding(base64_decode($content), 'UTF-8', 'KOI8-R');
    }

}
这对我有好处:

foreach ($mail as $message) {

    $content = null;      
    foreach (new RecursiveIteratorIterator($message) as $part) {
        if (strtok($part->contentType, ';') == 'text/plain') {
            $content = $part;
            break;
        }
    }

    if ($content) {
        echo "\n encode: " . $content->contentTransferEncoding;        
        echo "\n date: " . $message->date;
        echo "\n subject: \n" . iconv_mime_decode($message->subject, 0, 'UTF-8');
        echo "\n plain text part: \n" . mb_convert_encoding(base64_decode($content), 'UTF-8', 'KOI8-R');
    }

}

您能否提供您尝试解析失败的消息的完整且未经编辑的原始版本?这听起来好像不是一个格式良好的MIME消息,但如果是这样的话,你应该得到一个例外。这是否有帮助:@Charles这是一个机密信息,所以我不能共享编码的部分。。当它被解码后,我得到了一个html输出,我在gmail上看到了它。@Sudhir,这不是我要找的。。不管怎样,我还是发现了问题。。我必须使用getPart()单独获取邮件部分。您能否提供您试图解析但未成功的邮件的完整且未经编辑的原始版本?这听起来好像不是一个格式良好的MIME消息,但如果是这样的话,你应该得到一个例外。这是否有帮助:@Charles这是一个机密信息,所以我不能共享编码的部分。。当它被解码后,我得到了一个html输出,我在gmail上看到了它。@Sudhir,这不是我要找的。。不管怎样,我还是发现了问题。。我必须使用getPart()单独获取邮件部分。我直接使用getPath来完成这项工作。。但在某些情况下,它并不是以引用的可打印编码为基础的。。我找不到使用base64解码或引用的可打印解码的“内容传输编码”类型。。请建议……我不明白你的意思。标题中有内容传输编码:base64。我已经为您编辑了标题。我没有看到编辑。。但getHeaders函数未返回内容传输编码。。我想我必须先得到部分和标题。。我会检查并让你知道..我直接使用getPath来做这项工作。。但在某些情况下,它并不是以引用的可打印编码为基础的。。我找不到使用base64解码或引用的可打印解码的“内容传输编码”类型。。请建议……我不明白你的意思。标题中有内容传输编码:base64。我已经为您编辑了标题。我没有看到编辑。。但getHeaders函数未返回内容传输编码。。我想我必须先得到部分和标题。。我查一查,然后告诉你。。