Login   Register  
PHP Classes
elePHPant
Icontem

receive mail

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      POP3 e-mail client  >  All threads  >  receive mail  >  (Un) Subscribe thread alerts  
Subject:receive mail
Summary:just like header,body,attachment file
Messages:11
Author:liu chun fong
Date:2011-11-10 06:50:56
Update:2011-11-23 00:59:15
 
  1 - 10   11 - 11  

  1. receive mail   Reply  
Picture of liu chun fong
liu chun fong
2011-11-10 06:50:57
Hello! I'm a new PHP programmer. For some reason,I have to use PHP to receive mails. therefore, I find your PHP class in Google that can receive mail via POP3.

I try to study your code, and now I can connect to Gmail in test_pop3.php.
But I have some questions.

Q1: What difference between RetrieveMessage function and (OpenMessage+GetMessage)function in pop3.php?
Does it use to get messages???

Q2: I can't understand browse_mailbox.php、parse_message.php and test_pop3.php function, because I feel browse_mailbox.php & test_pop3.php have some equal.

Q3: I want to get mail's header, body ,then store in my local or Database, which function or variable are useful??

Q4: If I want to store attachment file in my local or anyelse, MIMEparser is a solution?

Thank for looking my article,my English is so poor,hope you could not laugh me > <".

  2. Re: receive mail   Reply  
Picture of Manuel Lemos
Manuel Lemos
2011-11-10 07:44:13 - In reply to message 1 from liu chun fong
1. RetrieveMessage get you the whole message (or just a few lines) all at once. OpenMessage and GetMessage lets you read the message in small chunks at a time, so it does not exceed your PHP memory limits when you get a very large message.

2. test_pop3.php is an example of all features of the class including deleting message. browse_mailbox.php shows you how to open a POP3 mailbox and process all its messages using the MIME parser class. parse_message.php shows you how to parse a single message with the MIME parser class using the POP3 stream wrapper that lets you retrieve messages as if they were files.

3. Any of the above examples show you how to do that but be careful because if you get large messages you may halt your script processing whole message bodies at once in memory depending on the method that you pick.

4. Yes, MIME parser lets you parse any type of e-mail message and can store message body parts into files if you want.

  3. Re: receive mail   Reply  
Picture of liu chun fong
liu chun fong
2011-11-14 05:57:54 - In reply to message 2 from Manuel Lemos
thank you so much^^

  4. Re: receive mail   Reply  
Picture of liu chun fong
liu chun fong
2011-11-15 07:37:13 - In reply to message 3 from liu chun fong
Hello! Manuel Teacher.
Now, I can use MIME parser to fetch information which I want to.
But I can't understand below codes:

$parameters=array(
'File'=>$message_file,

// Read a message from a string instead of a file
// 'Data'=>'My message data string',

// Save the message body parts to a directory
// 'SaveBody'=>'D:\tmp',

// Do not retrieve or save message body parts
// 'SkipBody'=>1,
);

If I comment 'Data','SaveBody',and 'SkipBody', I will fetch the information of "$results['Data']",just like article contents.

Then if I cancel comments just like 'SaveBody'=>'D:\tmp', I can find XXX.txt in D:\tmp and XXX.txt will record article contents , but I can't find the information of "$results['Data']".

These conditions make me confused...May be because I don't know these meaning of variables...

So, could you tell me the functions of variable about 'File','Data','SaveBody' and 'SkipBody'??

thank you very much, Teacher.

  5. Re: receive mail   Reply  
Picture of Manuel Lemos
Manuel Lemos
2011-11-15 09:20:44 - In reply to message 4 from liu chun fong
In case you have not noticed, the MIME parser class comes with documentation that explains all those parameters.

Anyway, if you use the SaveBody parameters, the class saves the data of body parts to files, so those body parts data is not returned in variables, as it may be too large to fit within the PHP memory limits.

  6. Re: receive mail   Reply  
Picture of liu chun fong
liu chun fong
2011-11-16 10:48:35 - In reply to message 5 from Manuel Lemos
Thank you very much!!

Although the variable have comments, I still can't understand the meaning of 'Data', 'SkipBody'. But now I can use 'SaveBody' to store file in my localhost.

Q1:Are 'SaveBody' and 'SkipBody' exclusive??

Because you say that 'SaveBody' will 'Save the message body parts to a directory', and 'SkipBody' is 'Do not retrieve or save message body parts', It makes me confused.


Q2:What the 'Data' variable meaning?

It say if I have files just like aaa.txt, I can write 'Data' = D:\pic\aaa.txt(the routing just a example)??


Q3:I can fetch attachment file(e.g:the picture named 1234.jpg),
I use $results['Attachment'][0]['Data'] to achieve my goal, but when I echo $results['Attachment'][0]['Data'], it will output garbage characters. so, it can't output normal characters.

Your example 'browse_mailbox.php' can output
S(Server?) /9j/4AAQSkZJRgABAgAAAQABAAt
S(Server?) bnRyUkdCIFhZWiAH2QADABsAFQAkAB9hY3NwAAAAAAAAAAAAAAAAAA...etc

I use $results['Attachment'][0]['Data'] may be output
descDybXYZ&#65533;bTRC&#65533; dmdd
&#61415;&#61449;&#61514;&#65533;&#65533;&#128;&#61712;&#61747;&#61813;...etc


Thank you, teacher.

  7. Re: receive mail   Reply  
Picture of Manuel Lemos
Manuel Lemos
2011-11-16 19:26:19 - In reply to message 6 from liu chun fong
SkipBody is just for telling the class to not parse the message body contents.

SaveBody is about what to do with the results of parsing. In that case the result is to save the body parts to files.

Data is to use when you have the whole message contents in a string. It is not a file name, it is the message contents.

The contents of a JPEG image are binary. If you try to output the contents of that image as text, it shows garbage, not the image. To show the image as image in a browser you cannot dump its contents as text. You need to send the header Content-type: image/jpeg and then you output image data contents.

The debug output shows what comes and goes to the server. Usually it is encoded using base64, so all characters are readable.

  8. Re: receive mail   Reply  
Picture of liu chun fong
liu chun fong
2011-11-20 18:52:46 - In reply to message 7 from Manuel Lemos
Oh...I seem to understand What you say.

For the JPEG,my code is below:

$data = base64_decode($results['Attachment'][0]['Data']);
$im = imagecreatefromstring($data);
$filename = 'D:/test.jpg';

echo "<PRE>$filename</PRE>\n";

if ($im !== false) {
header('Content-Type: image/jpeg');
imagejpeg($im, $filename);
echo 'Image success';
}
else {
echo '<PRE>An error occured.</PRE>\n';
}

Above the code,I wrote something wrong?? Because it always output 'An error occured' XD...

  9. Re: receive mail   Reply  
Picture of Manuel Lemos
Manuel Lemos
2011-11-20 20:02:08 - In reply to message 8 from liu chun fong
No, the attached files are always decoded by the MIME parser class, so you do not need to use base64_decode.

If you still get an error, you need to tell me what is the whole error message so I can advise.

  10. Re: receive mail   Reply  
Picture of liu chun fong
liu chun fong
2011-11-22 20:12:59 - In reply to message 9 from Manuel Lemos
Hello, teacher!

My PHP tool is netbeans, I have not still been skillful for that,
I give you a PDF that it has browse_mailbox.php output.

The web address is
http://www.scribd.com/fullscreen/73502813?access_key=key-2nc ...

So...if you can look this PDF, you will see the $results['Attachment'][0]['Data'] output is garbage characters, I can't find a useful way to solve it.

By the way, my language is Chinese, if the e-mail title or content is Chinese, could the output become garbage characters???


 
  1 - 10   11 - 11