Reading emails from gmail using PHP & IMAP

Recently i have worked on language translation project for that i need to read emails using PHP From the gamil inbox based on the email content i had created projects in the database…fortunately reading email from the gmail was easier than i think thanks to IMAP extension.

Here is the simple example for retrieving emails from the gmail:

NOTE: This will work only if you meet the fallowing requirements

  • PHP version should be PHP5 or latest
  • PHP IMAP Extension should be enabled in your PHP installation
  • IMAP should be enabled in your Gmail settings.

How to enable IMAP in PHP

How to Enable IMAP in XAMPP

IMAP is not enabled by default in Xampp distribution, so to enable it go to the file "\xampp\php\php.ini" and search for ";extension=php_imap.dll" and by removing the beginning semicolon at the line ,it’s get enabled ,it should be: extension=php_imap.dll.

How to enable IMAP in Linux

You can install the PHP5 IMAP module with this command :

apt-get install php5-imap

However it’s not enabled by default so enable it with:

php5enmod imap

To see the changes ,restart Apache

service apache2 restart

Here is the PHP script for retrieve Your Gmail Emails Using IMAP.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

I am Arjun from Hyderabad (India). I have been working as a software engineer from last 7+ years, and its my passion to learn new things and implement them as a practice. Aside from work, I likes gardening and spending time with pets. Protection Status