1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | <!doctype html> <html> <head> <title>Read GMail with IMAP</title> <meta charset= "utf-8" /> <script src= "jqmin.js" type= "text/javascript" ></script> <script type= "text/javascript" > $(document).ready( function () { $( 'div.body' ).slideUp( 'slow' ); $( 'div.toggler' ).click( function () { $(this).addClass( 'read' ).removeClass( 'unread' ); $(this).next( 'div.body' ).slideToggle( 'slow' ); }); }); </script> <style type= "text/css" > div.toggler { border: 1px solid #ccc; cursor: pointer; padding: 10px 32px; } div.toggler .subject { font-weight: bold; } div.read { color: #666; } div.toggler .from, div.toggler . date { font-style: italic; font-size: 12px; } div.body { border: solid thin #7f7f7f; padding: 10px 20px; } </style> </head> <body> <?php /* connect to gmail */ $hostname = '{imap.gmail.com:993/imap/ssl}INBOX' ; $username = 'your_account@gmail.com' ; $password = 'your_password' ; /* try to connect */ $inbox = imap_open( $hostname , $username , $password , OP_READONLY) or die ( 'Cannot connect to Gmail: ' . imap_last_error()); /* grab emails */ $emails = imap_search( $inbox , 'UNSEEN' ); /* if emails are returned, cycle through each... */ if ( $emails ) { /* begin output var */ $output = '' ; /* for every email... */ foreach ( $emails as $email_number ) { /* get information specific to this email */ $overview = imap_fetch_overview( $inbox , $email_number , 0); $message = imap_utf8(imap_fetchbody( $inbox , $email_number , 2)); /* output the email header information */ $output .= '<div class="toggler ' .( $overview [0]->seen ? 'read' : 'unread' ). '">' .PHP_EOL; $output .= '<span class="subject">' .imap_utf8( $overview [0]->subject). '</span> ' ; $output .= '<span class="from">' .imap_utf8( $overview [0]->from). '</span> ' ; $output .= '<span class="date">on ' . $overview [0]-> date . '</span>' ; $output .= '</div>' .PHP_EOL; /* output the email body */ $output .= '<div class="body">' . $message . '</div>' .PHP_EOL; } echo $output ; } /* close the connection */ imap_close( $inbox ); ?> </body> </html> |
رتبه موضوع:
مشاهده ایمیلهای خوانده نشده GMail
|
05-03-1394، 07:51 ب.ظ
تشکر شده توسط: meysam1366 , mtcom
05-03-1394، 09:09 ب.ظ
اگر اشتباه نکنم با کتابخونه phpmailer هم میشه اینکار رو انجام داد، این کتابخونه رو پیشنهاد میکنید یا استفاده از مجموعه توابع imap که اینجا استفاده کردید و این روش شما؟
05-03-1394، 09:14 ب.ظ
خود PHPMailer هم با POP3 کار میکنه که البته IMAP پروتکل جدیدتریه.
تشکر شده توسط: php , meysam1366 , mtcom
سلام این کد خطا میده موقع اجرا
Fatal error: Call to undefined function imap_open() extension imap رو هم توی php.ini فعال کردم توی xampp ولی بازم درست نشد
06-04-1394، 11:02 ق.ظ
Apache رو هم Restart کردین؟
06-04-1394، 11:04 ق.ظ
06-04-1394، 11:17 ق.ظ
چک کنید شاید هنوز فعال نشده. phpinfo بگیرین. اگه فعال نشده بود، DLL مناسب برای سیستم خودتون (32 یا 64 بیتی و Thread Safe یا Non Thread Sage بسته به نسخه PHP که نصب شده) رو دانلود و جایگزین DLL قبلی کنید.
تشکر شده توسط: mtcom
|
|
کاربران در حال بازدید این موضوع: