简体   繁体   English

php imap,从iphone发送的附有照片的电子邮件给出了奇怪的代码

[英]php imap, email sent from iphone with attached photo gives weird code

Here the context before the question : Context : I have a working web portal to send and receive emails.这里是问题之前的上下文: 上下文:我有一个可用的门户网站来发送和接收电子邮件。 I use imap_open with ressource, email pass, etc all that part is ok and working well for 99% of received emails我将 imap_open 与资源、电子邮件传递等一起使用,所有这些部分都可以,并且对于 99% 的收到电子邮件都运行良好

Question is the 1% not working Example : someone have a iPhone and send an email to me with attached photo.问题是 1% 不工作 示例:有人有一部 iPhone 并向我发送附有照片的电子邮件。

When I receive the email via my imap_open and imap_fetchbody and decoded according to imap encoding identified in the fetch_header... I get this当我通过 imap_open 和 imap_fetchbody 收到电子邮件并根据 fetch_header 中标识的 imap 编码进行解码时...我明白了

????EXIFMM* ???????? AppleiPhone........

why and how to fix it ?为什么以及如何解决它?

here a sample of my code that handles the decoding这是我处理解码的代码示例

switch ( $imap_encoding ) {
                            case 0 :    $imapx__fetchbody = $imapx__fetchbody; break;
                            case 1 :    $imapx__fetchbody = quoted_printable_decode(imap_8bit($imapx__fetchbody)); break;
                            case 2 :    $imapx__fetchbody = imap_binary($imapx__fetchbody); break;
                            case 3 :    $imapx__fetchbody = imap_base64($imapx__fetchbody); break;
                            case 4 :    $imapx__fetchbody = quoted_printable_decode($imapx__fetchbody); break;
                            default :   $imapx__fetchbody = $imapx__fetchbody; break;
                        }

//test body if base64 because some emails have  miss identified imap_encoding
if ( base64_encode(base64_decode($imapx__fetchbody, true)) === $imapx__fetchbody){ $imapx__fetchbody = imap_base64($imapx__fetchbody); }

here a full body sample这里是全身样本

在此处输入图片说明

you should read this :你应该读这个:

https://www.php.net/manual/en/function.image-type-to-mime-type.php https://www.php.net/manual/en/function.image-type-to-mime-type.php

if shows you how to determine the image type. if 向您展示如何确定图像类型。 Specially for EXIF you must take this functions特别是EXIF你必须带这个功能

https://www.php.net/manual/en/function.exif-read-data.php https://www.php.net/manual/en/function.exif-read-data.php

and

https://www.php.net/manual/en/function.exif-imagetype.php https://www.php.net/manual/en/function.exif-imagetype.php

You have two functions for decoding exif您有两个用于解码 exif 的函数

Configuration options
----------------------
exif.encode_unicode             "ISO-8859-15"
exif.decode_unicode_motorola    "UCS-2BE"
exif.decode_unicode_intel       "UCS-2LE"
exif.encode_jis                 ""
exif.decode_jis_motorola        "JIS"
exif.decode_jis_intel           "JIS"

Then you can write something like : 

<?php

    if (exif_imagetype('image.jpg') != IMAGETYPE_JPEG) {

      echo 'The picture is a JPEG';

      ini_set('exif.decode_unicode_motorola', 'UCS-2LE');

      $data = exif_read_data('exifPicture.jpg');

      var_dump($data);

    }

?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM