On Jul 26, 3:49 am, sonja.che...@gmail.com wrote:
Hello !
I'm looking for a script which allows me to read emails and attachment
from a pop server (then I'll save the email's text in a db and the
attachments on the server).
So I have found this article:http://www.phpit.net/article/read-email-php-pop3/
...
$email = $pop3->get_mail($i); // how to get the email
...
But then how do I get the information about my attachments and how can
I save them?
Thanks a lot
Sonja
Hi, I may not be the best to respond to this, since I am not familiar
with reading the pop3 e-mail through php at all...but I do know that
with e-mails, attachments are encoded right in the text of the
message, if you save a message and view it in a text editor, you will
likely see the encoded text for your attachement(s).
In the headers for the e-mail message you will find a section similar
to:
------=_NextPart_000_001C_01C7C9E5.56D0D990
Content-Type: multipart/alternative;
boundary="----=_NextPart_001_001D_01C7C9E5.56D32380"
Directly above the encoded attachment will be a section similar to:
------=_NextPart_000_001C_01C7C9E5.56D0D990
Content-Type: application/x-zip-compressed;
name="BELL REPLACEMENT FILES.zip"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="BELL REPLACEMENT FILES.zip"
------=_NextPart_000_001C_01C7C9E5.56D0D990--
As you notice the content in the mail is encoded as base64.
Where ever the string after the boundary= portion is, will be either
the e-mail message itself, content-type info, or the attachment data
itself. Once you get your text from the e-mail file that is the
encoded attachment, you could probably use:
$file_as_str=base64_decode($encoded_string);
which you should then be able to just output the contents of the
base64_decode results to a file to have the attachment file saved, or
place the data in a blob in a mysql table or whatever you would choose
to do with it. Hopefully that makes sense.