Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function test()
- {
- /* connect to gmail */
- $hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
- $username = 'youremail';
- $password = 'yourpassword';
- $inbox = imap_open($hostname, $username, $password) or die('Cannot connect: ' . imap_last_error());
- $emails = imap_search($inbox, 'ALL');
- if ($emails) {
- $output = '';
- rsort($emails);
- foreach ($emails as $email_number) {
- $header = imap_headerinfo($inbox, $email_number);
- $from = $header->from[0]->mailbox . "@" . $header->from[0]->host;
- $toaddress = $header->toaddress;
- echo '<strong>To:</strong> ' . $toaddress . '<br>';
- echo '<strong>From:</strong> ' . $from . '<br>';
- $message = quoted_printable_decode(imap_fetchbody($inbox,$email_number,1.1));
- if ($message == '') {
- $message = (imap_fetchbody($inbox, $email_number, 1));
- echo '<strong>Body:</strong> ' . $message . '<br>';
- echo '<br>';
- }
- }
- }
- imap_expunge($inbox);
- imap_close($inbox);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement