php imap 附件,PHP IMAP电子邮件附件无法访问某些电子邮件

我正在尝试使用imap从电子邮件中获取电子邮件附件,

该脚本适用于大多数电子邮件,但一个发件人附件似乎有问题,无法检索PDF附件.

我的代码在这里

$hostname = '{mail.testserver.com:993/tls}INBOX';

$username = 'test@testserver.nl';

$password = 's1M@F1225224';

/* try to connect */

$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Email Server: ' . imap_last_error());

/* grab emails */

$emails = imap_search($inbox,'FROM "info@test.com"');

count($emails);

/* if emails are returned, cycle through each... */

if($emails) {

/* begin output var */

$output = '';

$io=0;

/* put the newest emails on top */

rsort($emails);

/* for every email... */

foreach($emails as $email_number){

echo $io++;

echo '
';

$int='';

/* get information specific to this email */

$overview = imap_fetch_overview($inbox,$email_number,0);

$message = imap_fetchbody($inbox,$email_number,1);

$headerx = imap_headerinfo($inbox,$email_number,0);

// get first mails header

$structure = imap_fetchstructure($inbox, $email_number);

//var_dump( $structure );

$attachments = array();

/* if any attachments found... */

if(isset($structure->parts) && count($structure->parts))

{

for($i = 0; $i < count($structure->parts); $i++)

{

echo 'dump of mail structure

';

var_dump($structure->parts[$i]);

echo '

';

$attachments[$i] = array(

'is_attachment' => false,

'filename' => '',

'name' => '',

'attachment' => ''

);

if($structure->parts[$i]->ifdparameters)

{

//dparameters

foreach($structure->parts[$i]->ifdparameters as $object)

{

echo $object->attribute;

if(strtolower($object->attribute) == 'filename')

{

$attachments[$i]['is_attachment'] = true;

$attachments[$i]['filename'] = $object->value;

}

}

}

if($structure->parts[$i]->ifparameters)

{

foreach($structure->parts[$i]->parameters as $object)

{

if(strtolower($object->attribute) == 'name')

{

$attachments[$i]['is_attachment'] = true;

$attachments[$i]['name'] = $object->value;

}

}

}

if($attachments[$i]['is_attachment'])

{

$attachments[$i]['attachment'] = imap_fetchbody($inbox, $email_number, $i+1);

/* 3 = BASE64 encoding */

if($structure->parts[$i]->encoding == 3)

{

$attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']);

}

/* 4 = QUOTED-PRINTABLE encoding */

elseif($structure->parts[$i]->encoding == 4)

{

$attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']);

}

}

}

}

echo '

';

var_dump($attachments);

echo '

';

break;

}

var dump of structure part $structure-> parts [$i]

object(stdClass)#36 (11) {

["type"]=>

int(1)

["encoding"]=>

int(0)

["ifsubtype"]=>

int(1)

["subtype"]=>

string(11) "ALTERNATIVE"

["ifdescription"]=>

int(0)

["ifid"]=>

int(0)

["ifdisposition"]=>

int(0)

["ifdparameters"]=>

int(0)

["ifparameters"]=>

int(1)

["parameters"]=>

array(1) {

[0]=>

object(stdClass)#78 (2) {

["attribute"]=>

string(8) "boundary"

["value"]=>

string(51) "--boundary_278_245b5f5d-6ca6-49f9-adc5-9723088add21"

}

}

["parts"]=>

array(2) {

[0]=>

object(stdClass)#74 (12) {

["type"]=>

int(0)

["encoding"]=>

int(4)

["ifsubtype"]=>

int(1)

["subtype"]=>

string(5) "PLAIN"

["ifdescription"]=>

int(0)

["ifid"]=>

int(0)

["lines"]=>

int(14)

["bytes"]=>

int(891)

["ifdisposition"]=>

int(0)

["ifdparameters"]=>

int(0)

["ifparameters"]=>

int(1)

["parameters"]=>

array(1) {

[0]=>

object(stdClass)#32 (2) {

["attribute"]=>

string(7) "charset"

["value"]=>

string(5) "utf-8"

}

}

}

[1]=>

object(stdClass)#49 (11) {

["type"]=>

int(1)

["encoding"]=>

int(0)

["ifsubtype"]=>

int(1)

["subtype"]=>

string(7) "RELATED"

["ifdescription"]=>

int(0)

["ifid"]=>

int(0)

["ifdisposition"]=>

int(0)

["ifdparameters"]=>

int(0)

["ifparameters"]=>

int(1)

["parameters"]=>

array(2) {

[0]=>

object(stdClass)#38 (2) {

["attribute"]=>

string(4) "type"

["value"]=>

string(9) "text/html"

}

[1]=>

object(stdClass)#67 (2) {

["attribute"]=>

string(8) "boundary"

["value"]=>

string(51) "--boundary_279_c12a0e86-9df1-42b4-a007-c75d5904de9f"

}

}

["parts"]=>

array(2) {

[0]=>

object(stdClass)#58 (12) {

["type"]=>

int(0)

["encoding"]=>

int(4)

["ifsubtype"]=>

int(1)

["subtype"]=>

string(4) "HTML"

["ifdescription"]=>

int(0)

["ifid"]=>

int(0)

["lines"]=>

int(43)

["bytes"]=>

int(3263)

["ifdisposition"]=>

int(0)

["ifdparameters"]=>

int(0)

["ifparameters"]=>

int(1)

["parameters"]=>

array(1) {

[0]=>

object(stdClass)#25 (2) {

["attribute"]=>

string(7) "charset"

["value"]=>

string(5) "utf-8"

}

}

}

[1]=>

object(stdClass)#69 (12) {

["type"]=>

int(5)

["encoding"]=>

int(3)

["ifsubtype"]=>

int(1)

["subtype"]=>

string(3) "PNG"

["ifdescription"]=>

int(0)

["ifid"]=>

int(1)

["id"]=>

string(15) ""

["bytes"]=>

int(16262)

["ifdisposition"]=>

int(0)

["ifdparameters"]=>

int(0)

["ifparameters"]=>

int(0)

["parameters"]=>

object(stdClass)#62 (0) {

}

}

}

}

}

}

object(stdClass)#66 (11) {

["type"]=>

int(1)

["encoding"]=>

int(0)

["ifsubtype"]=>

int(1)

["subtype"]=>

string(5) "MIXED"

["ifdescription"]=>

int(0)

["ifid"]=>

int(0)

["ifdisposition"]=>

int(0)

["ifdparameters"]=>

int(0)

["ifparameters"]=>

int(1)

["parameters"]=>

array(1) {

[0]=>

object(stdClass)#22 (2) {

["attribute"]=>

string(8) "boundary"

["value"]=>

string(51) "--boundary_281_2ef5384d-4be2-4276-b5be-0f73bcc0811d"

}

}

["parts"]=>

array(2) {

[0]=>

object(stdClass)#70 (13) {

["type"]=>

int(3)

["encoding"]=>

int(3)

["ifsubtype"]=>

int(1)

["subtype"]=>

string(3) "PDF"

["ifdescription"]=>

int(0)

["ifid"]=>

int(1)

["id"]=>

string(6) ""

["bytes"]=>

int(277524)

["ifdisposition"]=>

int(1)

["disposition"]=>

string(10) "attachment"

["ifdparameters"]=>

int(0)

["ifparameters"]=>

int(1)

["parameters"]=>

array(1) {

[0]=>

object(stdClass)#80 (2) {

["attribute"]=>

string(4) "name"

["value"]=>

string(15) "inv18701288.PDF"

}

}

}

[1]=>

object(stdClass)#63 (13) {

["type"]=>

int(3)

["encoding"]=>

int(3)

["ifsubtype"]=>

int(1)

["subtype"]=>

string(12) "OCTET-STREAM"

["ifdescription"]=>

int(0)

["ifid"]=>

int(1)

["id"]=>

string(6) ""

["bytes"]=>

int(77098)

["ifdisposition"]=>

int(1)

["disposition"]=>

string(10) "attachment"

["ifdparameters"]=>

int(0)

["ifparameters"]=>

int(1)

["parameters"]=>

array(1) {

[0]=>

object(stdClass)#55 (2) {

["attribute"]=>

string(4) "name"

["value"]=>

string(33) "Algemene leveringsvoorwaarden.pdf"

}

}

}

}

}

var dump of attachments数组

array(2) {

[0]=>

array(4) {

["is_attachment"]=>

bool(false)

["filename"]=>

string(0) ""

["name"]=>

string(0) ""

["attachment"]=>

string(0) ""

}

[1]=>

array(4) {

["is_attachment"]=>

bool(false)

["filename"]=>

string(0) ""

["name"]=>

string(0) ""

["attachment"]=>

string(0) ""

}

}

有人知道这个电子邮件内容或脚本有什么问题,是否有任何获得附件的解决方案,非常感谢

我认为附件对象结构与其他邮件不同,但我不知道如何获取它

解决方法:

检查您尝试附加的文件的pdf附件的大小,它可能超过php.ini允许的限制

标签:php,imap,email-attachments

来源: https://codeday.me/bug/20190710/1425899.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值