Jump to content

IMAP File Attachments


The Little Guy

Recommended Posts

How do I get these:

 

1. Body Text

2. The Attachment(s)

 

Here is what I have to get an attachment, but it doesn't work at all:

$info = imap_fetchstructure($imap, $msg);
$numparts = count($info->parts);
$attachment = '';
if ($numparts > 1) {
foreach ($info->parts as $part) {
	if ($part->disposition == "ATTACHMENT") {
		$attachment .= $part->dparameters[0]->value;
	}
}
}

 

I am able to read an email without an attachment, but not an email with an attachment.

 

 

more code:

$mbox = imap_open("{mail.dudeel.com/novalidate-cert}", "[email protected]", "xxxxxxx")or die();
$dir = 1;
$smail = imap_sort($mbox,SORTDATE,$dir);
if($smail){
foreach($smail as $msg){
	if(count($smail) > 0){
		$body = imap_fetchbody($mbox, $msg, "2");
		$headers = imap_headerinfo($mbox,$msg);

		if(empty($headers->subject)){
			$subject = "(No Subject)";
		}else{
			$subject = $headers->subject;
		}
		$to = $headers->to[0]->mailbox.'@'.$headers->to[0]->host;
		$personal = $headers->from[0]->personal; 
		$from = $headers->reply_to[0]->mailbox.'@'.$headers->reply_to[0]->host;


		$info = imap_fetchstructure($imap, $msg);

		$numparts = count($info->parts);
		$attachment = '';
		if ($numparts > 1) {
			foreach ($info->parts as $part) {
				if ($part->disposition == "ATTACHMENT") {
					$attachment .= $part->dparameters[0]->value;
				}
			}
		}
	}
}
}

Link to comment
https://forums.phpfreaks.com/topic/122188-imap-file-attachments/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.