There are 2465 emails in my gmail,why the program can't stop after download all the emails? All code1 and code2 are run in command line mode.
code1:
<?php $mailbox = array( 'mailbox' => '{imap.gmail.com:993/imap/ssl}INBOX', 'username' => '[email protected]', 'password' => 'yyyy' ); $stream = imap_open($mailbox['mailbox'], $mailbox['username'], $mailbox['password']) or die('Cannot connect to mailbox: ' . imap_last_error()); $emails = imap_search($stream,"ALL"); $nums=imap_num_msg($stream); echo $nums; foreach($emails as $email_id) { $mime = imap_fetchbody($stream, $email_id, ""); file_put_contents("/tmp/" . "email_{$email_id}.eml", $mime); } imap_close($stream); echo "over"; ?>
For code1 :
1.can download all the emails.
2.output 2465 on the console
3.no over
output on the console.
4.the program can't stop ,it seems to run forever.
code2:
<?php $mailbox = array( 'mailbox' => '{imap.gmail.com:993/imap/ssl}INBOX', 'username' => '[email protected]', 'password' => 'yyyy' ); $stream = imap_open($mailbox['mailbox'], $mailbox['username'], $mailbox['password']) or die('Cannot connect to mailbox: ' . imap_last_error()); $emails = imap_search($stream,"ALL"); $nums=imap_num_msg($stream); echo $nums; foreach($emails as $email_id) { echo $email_id.PHP_EOL; $mime = imap_fetchbody($stream, $email_id, ""); file_put_contents("/tmp/" . "email_{$email_id}.eml", $mime); } imap_close($stream); echo "over"; ?>
For code2:
1.can download all the emails.
2.output 2465 on the console .
3.over
output on the console.
4.the program stop after download all the emails.
There is one line echo $email_id.PHP_EOL;
in code2 more than code1,other codes are same.
All code1 and code2 are run in command line mode.
Who can explain it ?
If you download an email to your client and delete it while this option is selected, the copy left on the server will download again the next time you open your client. To avoid this happening, you can either set your mailbox up to use the IMAP protocol, or uncheck the option to “Leave a copy of my mail on the server”.
All you need to do is go to the sender you wish to block, click on the email, and then click on the sender's name. A menu will come up, and all you need to do is click 'Block this contact', and it's done. From then on, any emails they do send you should go straight to your Trash folder.
This behavior can occur if your Outlook profile contains two Internet accounts and both point to the same POP3 server. To resolve this issue, turn off email reception for one of the POP3 accounts: Go to Outlook > Tools > Send/Receive Settings > Click Define Send/Receive Groups.
The Mail app may fail to download the message from the email servers due to a temporary communication glitch or corruption of the email account on the device. In this context, turning off/on email or re-adding the email account to the Mail app may solve the problem.
Try
print imap_last_error();
Before and after imap_close
to know more about what causes your problem
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With