Accessing mail using IMAP in PHP not working for Gmail - php

I am using following server to connect to Gmail IMAP but it says "Can't open mailbox: no such mailbox"
{imap.gmail.com:993/ssl/novalidate-cert}
I have even tried the following but same error.
{imap.gmail.com:993/ssl}[Gmail]/All Mail
{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX
The email account does exist and IMAP is also enabled in my Gmail.

Try This
$hostname = "{imap.gmail.com:993/imap/ssl}INBOX";
$username = $imap_user;
$password = $imap_password;
$inbox = imap_open($hostname, $username, $password);//Open Mailbox
To Access any other mailbox like Archive you just Change INBOX to Archive or what ever folder name is and i think this folder names are case sensitive.
It Works for me.

Related

Accesing gmail from bluemix in php imap

I am trying to get mails from gmail account with php imap in bluemix application.
I believe it is a bluemix config issue.
I have enabled imap in the gmail acount.
In bluemix I added a file .user.ini and I wrote : extension=php_imap.dll
The php code is:
<?p
hp
set_time_limit(60);
/* connect to gmail with your credentials */
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'mygmailaccount#gmail.com';
$password = 'mypassword';
/* try to connect */
print_r('debug: just before accessing gmail');
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
print_r('debug: i did not die when accesing gmail ');
/*here is more code but I do not access this... */
?>
When I run this code I get the first debug message and that's all. no error or other debug.
I might guess that something with the imap.dll setting is wrong.
Can I have advice on this?
:)
In the application root directory create the following directory and file if not present:
.bp-config/options.json
The options.json file should have the following content:
{
"PHP_EXTENSIONS": ["imap"]
}
Push your application again using:
cf push
Make sure you have IMAP enabled in your Google account and also turn on access for less secure apps per link below:
https://support.google.com/accounts/answer/6010255
DISCLAIMER: Google does not recommend to turn on access for less secure apps.

integrate IMAP on php website

I am trying to integrate IMAP on website, but i am stuck in the first itself. I am not able to establish the connection. The code that I used was:
$connect_to = '{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX';
//$connect_to = '{imap.gmail.com:993/imap/ssl}INBOX'; tried this method also
$user = 'abc#gmail.com';
$password = 'abc123';
$connection = imap_open($connect_to, $user, $password)
or die("Can't connect to '$connect_to': " . imap_last_error());
imap_close($connection);
I checked the firewall, authentication from gmail, allowed less secure app from gmail end, but everytime i am getting this error
Can't connect to '{imap.gmail.com:993/imap/ssl}INBOX': Can not authenticate to IMAP server: [ALERT] Please log in via your web browser: https://support.google.com/mail/account
Can anyone please tell why this is happening and how can i rectify it. I also would like to know is there a way where i can allow all web mails together, currently its only for gmail but i would like it to work for all server such as yahoo, hotmail, aol etc

Unable to connect to Gmail, using php imap

I'm trying to use imap with php to retrieve mails from gmail using the following code:
<?php
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'myaccount#gmail.com';
$password = 'mypassword';
$inbox = imap_open($hostname,$username,$password)
or die('Cannot connect to Gmail: ' . imap_last_error());
?>
However, imap_last_error throws me the following error:
"Unable to create TCP socket: Address family not supported by protocol"
I have imap enabled on my gmail account. imap 2007e with ssl (and OpenSSL) and kerberos seems to be enabled on the webserver. I don't have control on the domains ports, but support told me "Outgoing IMAP connections can be made, this is not blocked.".
I see I'm not the only one having trouble connecting to gmail using IMAP. However, I didn't find anyone who encountered this error.

Access emails using imap

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 = "my_email#gmail.com";
$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
Here is the solution:
Login to your gmail account, enable imap.
Let the access here first: https://www.google.com/settings/security/lesssecureapps
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
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
Try this (you need to turn on your Outbound relay):
Log into your account at google.com/a/yourdomain.com
Click the Settings tab and then select Email in the left column.
In the Outbound relay section, select Allow users to send mail through an external SMTP when configuring a "from" address hosted outside your domain.
Click Save changes.

Cpanel IMAP Gmail problems?

I'm trying to connect to my gmail account via IMAP on a 000webhost domain but I doesn't seem to be working even though they say that they support IMAP
Here's my PHP code:
$server="{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
$inbox = imap_open($server,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
for "$username" and "$password" I'm using my Gmail email and my Gmail password (e.g. myaccount#gmail.com and mypassword)
This just gives me an error saying that it can't open the stream and that it is an invalid remote specification.
Any ideas of what this might be?
Thanks in advance.
Gmail uses just the account name as login, not the full email address.

Categories