J
J
joger2011-03-25 21:51:31
PHP
joger, 2011-03-25 21:51:31

Zend_Mail attachment

Good evening,
there are moments when something doesn't work out for a long time and then the poor computer is in danger.
don't let him die :)
Task: take the soap out of the box and parse the attachment. business then ...
in order not to suffer, I decided to use Zend_Mail.
I am connected to the server I take
away soap
In all examples check on is_multipart and take away 2. a part.
My check for a multipart passes, but only when I try to pick up 2. part we get “there is no such part” on the forehead (during the enumeration it turned out that there are no parts there)
If we display the content of the soap on the screen, we get something like: i.e. e. "parts" is Where can be a mistake here? here is an example:
Mail von ...': bla multipart/mixed; boundary="------------080707010901070105060904"
This is a multi-part message in MIME format. ------=_NextPart_000_0060_01CBD118.8803ECD0 Content-Type: text/plain; format=flowed; charset="iso-8859-1" Content-Transfer-Encoding: 8bit bla -- ....... ------=_NextPart_000_0060_01CBD118.8803ECD0 Content-Type: text/plain; name="reports.txt" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="reports.txt" .....


// Connecting with Imap
$mail = new Zend_Mail_Storage_Imap(
array('host' => 'SERVER',
'user' => 'USERNAME',
'password' => 'PASSWORD'));

// Navigate to desired folder
$folder = $mail->getFolders()->INBOX->Info;

// Change to folder
$mail->selectFolder($folder);

// Loop through messages

foreach ($mail as $message)
{

// Find desired message subject

if($message->subject == 'SUBJECT')
{
// Check for attachment
if($message->isMultipart())
{
$part = $message->getPart(2);
}

// Get the attacment file name
$fileName = $part->getHeader('content-description');

// Get the attachement and decode
$attachment = base64_decode($part->getContent());

// Save the attachment
$fh = fopen($fileName, 'w');

fwrite($fh, $attachment);

fclose($fh);
}
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anatoly, 2011-03-25
@taliban

If no one tells me, I would advise debugging =) Debugging zend is an exciting activity :)

A
AlexeyK, 2011-03-25
@AlexeyK

The official manual uses $message = getPart(1);and explains how to pull such a message, try as they say, and if it doesn't work, ask why :-)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question