Accesing gmail from bluemix in php imap - php

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.

Related

Can't connect to gmail-imap.l.google.com,993: Connection refused

<?php
require "vendor/autoload.php";
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'mail#gmail.com';
$password = 'password';
$inbox = imap_open($hostname,$username ,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
He constantly writes that access is denied. The feeling of being closed by Google security. Where to allow access for no message:
Can't connect to gmail-imap.l.google.com, 993: Connection refused
Website https://pomidor.cc
Something on your network -- possibly a firewall -- is blocking your connection to the Google mail server. Contact your system administrator or hosting provider for details.
From the information you provided, it looks like a problem related with a missing certificate on your end. Here are a couple of questions with workarounds/solutions [1][2].
You may also consider to start using the Gmail API which allows you to do several actions in a simple way. You can enable the IMAP setting [3] and set the quickstart so you can start making requests from there [4].
[1] Connect to Gmail with PHP & IMAP
[2] Certificate error using IMAP in PHP
[3] https://developers.google.com/gmail/api/v1/reference/users/settings/updateImap
[4] https://developers.google.com/gmail/api/quickstart/php
I had the same problem and what solved it for me was 2 things:
I used my own password instead of the app password which you can
generate here
Instead of {imap.gmail.com:993/imap/ssl}INBOX i used
{localhost:993/imap/ssl/novalidate-cert}INBOX

imap php not working

I am trying to run imap_open() in on my server but its giving me this error.
Warning: imap_open(): Couldn't open stream {imap.gmail.com:993/imap/ssl}INBOX in /home/bestinsaudi2/public_html/mailbox.php on line 55
Cannot connect to Gmail: Can not authenticate to IMAP server: [ALERT] Please log in via your web browser: https://support.google.com/mail/acco
I have enabled imap in gmail account i am using .I also enabled less secure apps. I copied code from david walsh . His credentials is giving this error.
Warning: imap_open(): Couldn't open stream {imap.gmail.com:993/imap/ssl}INBOX in /home/bestinsaudi2/public_html/mailbox.php on line 55
Cannot connect to Gmail: Can not authenticate to IMAP server: [AUTHENTICATIONFAILED] Invalid credentials (Failure)
I am writing down the code i am using with my own credentials.
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'myemail#gmail.com';
$password = 'mypassword';
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
here is one more thing i am not using wamp or xamp server i am using ipower. Somewhere i found to run command like $ composer require secit-pl/imap-bundle
And its confusing .How to and where to run this and is it necessary with my code? Also do i have to download any library for this ? or should some additional step?
If less secure apps are enabled, and the app password is not working or not desired, it might be that google has found the IP address that your imap is using to be suspicious and blocked it.
Log into that account from a browser and check for an email from that has the subject "Critical security alert". The date on the email should be around the same time that imap stopped working. If you find such an email, it should spell out that a sign-in attempt was blocked, and have a big button that says "Check activity". When you click the button, it will ask if the sign in that it blocked was actually from you. Indicate that it was, and you should be able to sign in with imap again from that IP.
If you or someone else has already indicated that it was or was not them, there is an option to change your answer.
When google decides to do this, it only sends a single email. So if it's been a few days, that email might be buried in the inbox. It does not get resent for each blocked sign in from that IP.
You are probably looking for gmail setup for something called "Less Secure Apps":
https://support.google.com/accounts/answer/6010255?hl=en
that's why it requires you to log in with a browser.
After you set this up correctly, and enable less secure apps, this should work nicely, just checked with my own account.
EDIT: is safe apps is alredy enabled, you may need to create App Password:
https://support.google.com/mail/answer/185833?hl=en
and change your credentials to:
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'email#gmail.com';
$password = 'app password here, not your gmail password';
EDIT2: App Password functionality require to have 2-Step verification enabled

Read email with IMAP and PHP - Connection Refused

I want to read a mail's inbox using PHP IMAP.
On phpinfo() i see both OpenSSL and IMAP enabled.
When trying to connect:
/* connect to inbox */
$hostname = "{imap-mail.outlook.com:993/imap/tls}INBOX";
$username = 'mail#...';
$password = 'password';
/* try to connect */
$inbox = imap_open($hostname,$username,$password) or die('Error: ' . imap_last_error());
It will always throw an error:
Can't connect to imap.glbdns2.microsoft.com,993: Connection refused (errflg=2)
On the outlook settings it says:
Why does this happen and how can I fix it?
I had almost the same problem with my email server. It was not accepting request from other third party servers which was using it. After sometimes, it came down to the increased banning rules I had set for the server. The fail2ban was now set to permanently ban offending IPs which tried to unsuccessfully login for more than three times. I was lucky since I managed this email server myself so I un-blacklisted the IP and it works fine. Firewall problem is the most likely cause of this. Try the following:
check your IP if it is blacklisted by any blacklist houses (the requesting server IP);
a site like https://mxtoolbox.com/ can help;
if you have another server (like VPS container), try running the code from it;
if all fails, you may have to contact the: imap-mail.outlook.com people for help.

Connecting to Gmail IMAP PHP "Couldn't open stream"

There are lots of people having similar issues but no one is answering their questions. I have IMAP enabled in PHP, Using all the correct information. I don't see where I'm going wrong.
Here's my code:
$hostname = '{imap.gmail.com:995/imap/ssl/novalidate-cert}';
$username = 'emailaddress#gmail.com'; $password = 'password';
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
print_r(imap_errors());
Not returning any errors other than:
Warning: imap_open() [function.imap-open]: Couldn't open stream
{imap.gmail.com:995/imap/ssl/novalidate-cert} in
/home/a8066360/public_html/test/imap.php on line 6
Cannot connect to Gmail: Can't connect to gmail-imap.l.google.com, 995:
Connection timed out
I've noticed that if I change the single quotes to `
shell_exec() has been disabled for security reasons...
Please help!!!
You need port 993, the SSL IMAP port.
Port 995 is the SSL POP3 port.
I think Gmail's IMAP can only be accessed on port 993.
$hostname = "{imap.gmail.com:993/imap/ssl/novalidate-cert}";
I had the same error and found a different solution. I have added debug info into host:
"{imap.gmail.com:993/debug/imap/ssl/novalidate-cert}INBOX";
When I read php error log, I found
Unknown: [ALERT] Please log in via your web browser: https://support.google.com/mail/accounts/answer/78754 (Failure) (errflg=1) in Unknown on line 0
Open link, and follow instructions. Search for
Your app might not support the latest security standards. Try changing
a few settings to allow less secure apps access to your account.
Click on link and enable less secure app access.
Then it works for me.
You have to enable the
Google Enable Less Secure App option from Gmail account get connected.
And a requirement for this, you have to first disable your 2-step-verification from here:
google account -> settings -> security
You can try the following code by giving a notls argument and connecting the server like follows, if SSL is not applied.
$hostname = '{imap.YOUR_DOMAIN.com:143/imap/notls}INBOX';
$username = 'YOUR_USERNAME';
$password = 'YOUR_PASSWORD';
$inbox = imap_open($hostname, $username, $password) or die('Cannot connect to Gmail: ' . imap_last_error());
If it will not throw any error, this means that you are succesfully connected to server then. I hope this helps.
I had the same issue and I fixed it by unlocking the Google captcha.
Go to the following URL while signed in to the Google account :
https://accounts.google.com/DisplayUnlockCaptcha
And click on the button.
Of course, you already had activated the access for less secure apps in the Security tab of your Google account settings ;).
It should work now !
You can setup 2 step authentication and then assign an APP password to use in your requests (just replace your password with the one provided for the app, your normal password doesn't change.).
This will help your script run from any host without google blocking it (due to a change in login location).

Accessing mail using IMAP in PHP not working for Gmail

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.

Categories