1
votes

I am working on a project in which I have to fetch data from gmail inbox and save it into mysql database using php. I tried different code but it shows different errors like:

imap_open(): Couldn't open stream {imap.gmail.com:993/imap/ssl}INBOX

and also saw a notice that is

Too many login failures (errflg=2) in Unknown on line 0

I am working on Windows 8 and using php version 5.4.12.

Below is my code:

<?php
 $email = "[email protected]";//or my gmail account
 $password = "my gmail paasoward";
 $imap_host = "{imap.gmail.com:993/imap/ssl}";
 $imap_folder = "INBOX"; //it's what is called label in Gmail
 $mailbox = imap_open($imap_host . $imap_folder,$email,$password) or die('Failed to open connection with Gmail: ' . imap_last_error());
 $emails = imap_search( $mailbox, 'ALL');

 if ($emails) {
    foreach($emails as $email_id) {
        $email_info = imap_fetch_overview($mailbox,$email_id,0);
        $message = imap_fetchbody($mailbox,$email_id,2);

        echo "Subject: " . $email_info[0]->subject . "\n";
        echo "Message: " . $message . "\n";
    }
}
?>
2
can u give solutions what to do in it? I try my best but i didnt got any answer.. - user4417231
From the little information you give us I'd say you may have the username and password wrong or / and you don't have the ability to connect over ssl - Toby Allen
thank u but the username and password is correct. but about ssl connection i didnt found any solutions. can u give me solutions? - user4417231
Welcome to Stack Overflow! I edited your question to fix some mistakes and to improve on formatting - please see the editing help for more information on formatting. Good luck! - Wtower
Thank you for give me guidence. But anyone can give me solutions of my problem?? - user4417231

2 Answers

0
votes

it seems like that you have to enable the IMAP setup in the php.ini file, if you are using local xampp then go to the php.ini file where you have to remove the; option in the line of extension= php_imap.dll

0
votes

First go to the php.ini file, and here you find extenstion with relate to IMAP extenstion. it starts with semicolon ; you need to remove semicolon. after that a new file automatic created in folder php/ext you find a new file with name php_imap.dll, copy this and paste into windows/system32 folder. This is the extenstion, you need to edit.