Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access emails using imap

Tags:

php

apache

ubuntu

I am using Apache on Ubuntu 14.02 and running php on the same.I have connected to a remote mssql server hence no need of mysql .

I want to know how to connect to an email id registered with gmail in order to read the incoming emails .

I have tried the below , but it shows a blank screen while running it from my localhost :

<?php

error_reporting('E_ALL');
$mailboxPath = "{imap.gmail.com:993/imap/ssl}INBOX";
$username = "[email protected]";
$password = "mypassword";
$imap = imap_open($mailboxPath, $username, $password);
print_r($imap);

?>

I am inserting my actual gmail username and password while running the program . I want to know if i am missing something .

Many Thanks

like image 282
user3790233 Avatar asked Jul 02 '14 07:07

user3790233


1 Answers

Here is the solution:

  1. Login to your gmail account, enable imap.

  2. Let the access here first: https://www.google.com/settings/security/lesssecureapps

  3. Go to: https://accounts.google.com/b/0/DisplayUnlockCaptcha and enable access.

That's it.

I had the exact same problem when I try to get emails with imap on php. I was running the exact same script that I know it works with my other gmail.

The solution is above and the error message was:

ERROR: Can not authenticate to IMAP server: [ALERT] Please log in via your web browser

like image 98
Tarik Avatar answered Nov 03 '22 18:11

Tarik