Access emails using imap
Asked Answered
C

3

11

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

Condescend answered 2/7, 2014 at 7:29 Comment(3)
What's the output of imap_last_error()?Hoe
1) is your username and password correct? 2) change line $imap = imap_open($mailboxPath, $username, $password); into $imap = imap_open($mailboxPath, $username, $password) or die('Cannot connect to Gmail: ' . imap_last_error());. Now you will be noticed, why you can't connect into Gmail.Alodium
Hi ,thank you for the response ,below is my error : Cannot connect to Gmail: Can not authenticate to IMAP server: [ALERT] Please log in via your web browser: support.google.com/mail/accountsCondescend
S
35

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

Sharpe answered 27/8, 2015 at 1:13 Comment(1)
And default IMAP settings are just fine when you enable IMAP on your account settings. If you have problems moving the messages, make sure English - United States is selected on your profile language settings.Sharpe
B
0

Have you activated the imap.so extension in your php.ini file ? extension=imap.so it's a basical cause of issues on localhost server

Bowrah answered 2/7, 2014 at 7:39 Comment(2)
so you may don't have openSSL activated on your localhostBowrah
if it's not a ssl trouble, please log in to your gmail account with the link you've got in the error message a check if you have a message about a suspicious connection and validate the new client by entering your login and passwordBowrah
A
0

Try this (you need to turn on your Outbound relay):

  1. Log into your account at google.com/a/yourdomain.com
  2. Click the Settings tab and then select Email in the left column.
  3. In the Outbound relay section, select Allow users to send mail through an external SMTP when configuring a "from" address hosted outside your domain.
  4. Click Save changes.
Alodium answered 2/7, 2014 at 7:45 Comment(1)
I am not sure what you mean by google.com/a/yourdomain.com . I want to access a personalized gmail inbox . I do not see any settings or any tab to do with Outbound relay.Thank You.Condescend

© 2022 - 2024 — McMap. All rights reserved.