我已经坚持了几个小时。但基本上,我有一个收件箱,其中包含一些我想取出的内容和附件 PDF。我想出了如何取出我想要的所有 HTML,但是如何保存附加的 PDF?
这是我到目前为止的鳕鱼:
public function read_emails(){ // 设置用户检查
$strUser = "email";
$strPassword = "passwrd";
$delete_emails=false;
// open
$hMail = imap_open ("{webmail.somethingsomething.com:143/notls}INBOX", "$strUser", "$strPassword") or die("can't connect: " . imap_last_error());
// get headers
$aHeaders = imap_headers( $hMail );
// get message count
$objMail = imap_mailboxmsginfo( $hMail );
if($objMail != NULL)
{
// process messages
for( $idxMsg = 1; $idxMsg <= $objMail->Nmsgs; $idxMsg++ )
{
// get header info
$objHeader = imap_headerinfo( $hMail, $idxMsg );
// get from object array
$aFrom = $objHeader->from;
// process headers
for( $idx = 0; $idx < count($aFrom); $idx++ )
{
// get object
$objData = $aFrom[ $idx ];
// get email from
$strEmailFrom = $objData->mailbox . "@" . $objData->host;
//Get the subject
$message_subject = $objHeader->subject;
//Get the body of the message
$fullBody = imap_fetchbody($hMail,$idxMsg, 2);//displays full body including junk
$bodyMessage = quoted_printable_decode($fullBody);
//Get the msg structure
$message_structure = imap_fetchstructure($hMail, $idx);
//WHAT DO I DO HERE????
}
// delete message
if($delete_emails == true){
imap_delete( $hMail, $idxMsg );
}
}
// expunge deleted messages
if($delete_emails == true){
imap_expunge( $hMail );
}
//Clears the cache
imap_gc($hMail, IMAP_GC_ELT);
}
// close
imap_close( $hMail );
}
我有消息结构,如果我 print_r 可以看到其中一个部分有附件,我可以看到它是 PDF。不知道接下来会发生什么。我已经尝试过,但似乎无法找到一个好的解决方案。
谢谢!
编辑:这是 imap_fetchstructure 的内容
stdClass Object ( [type] => 1 [encoding] => 0 [ifsubtype] => 1 [subtype] => MIXED [ifdescription] => 0 [ifid] => 0 [ifdisposition] => 0 [ifdparameters] => 0 [ifparameters] => 1 [parameters] => Array ([0] => stdClass Object ([attribute] => boundary [value] => f46d044473ef81609f04d5f1997c)) [parts] => Array ([0] => stdClass Object ( [type] => 1 [encoding] => 0 [ifsubtype] => 1 [subtype] => ALTERNATIVE [ifdescription] => 0 [ifid] => 0 [ifdisposition] => 0 [ifdparameters] => 0 [ ifparameters] => 1 [parameters] => Array ([0] => stdClass Object ([attribute] =>boundary [value] => f46d044473ef81609b04d5f1997a)) [parts] => Array ([0] => stdClass Object ([ type] => 0 [encoding] => 0 [ifsubtype] => 1 [subtype] => PLAIN [ifdescription] =>0 [ifid] => 0 [lines] => 1 [bytes] => 37 [ifdisposition] => 0 [ifdparameters] => 0 [ifparameters] => 1 [parameters] => 数组 ( [0] => stdClass对象 ( [attribute] => charset [value] => ISO-8859-1 ) ) ) [1] => stdClass Object ( [type] => 0 [encoding] => 0 [ifsubtype] => 1 [subtype] => HTML [ifdescription] => 0 [ifid] => 0 [lines] => 1 [bytes] => 37 [ifdisposition] => 0 [ifdparameters] => 0 [ifparameters] => 1 [parameters] => Array ( [0] => stdClass Object ( [attribute] => charset [value] => ISO-8859-1 ) ) ) ) [1] => stdClass Object ( [type] => 3 [encoding] => 3 [ifsubtype] => 1 [subtype] => PDF [ifdescription] => 0 [ifid] => 0 [bytes] => 179876 [ifdisposition] => 1 [disposition] => 附件 [ifdparameters] => 1 [ d参数] =>Array ( [0] => stdClass Object ( [attribute] => filename [value] => Statement of Account.pdf ) ) [ifparameters] => 1 [parameters] => Array ( [0] => stdClass Object ( [ attribute] => name [value] => Statement of Account.pdf ) ) ) ) )