2

I moved from Netfirms to AWS. This code worked on Netfirms, but I get this error running on AWS:

Can not authenticate to IMAP server: [ALERT] - Can't connect to '{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX': 1.

$connect_to = '{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX';
$user = 'myaccount@gmail.com';
$password = 'mypassword';

$mbox = imap_open($connect_to, $user, $password) 
    or die("Can't connect to '$connect_to': " . print_r(imap_errors()));
Haymps
  • 91
  • 9
  • possible duplicate of [Connecting to Gmail through IMAP with PHP - SSL context failed](http://stackoverflow.com/questions/1274911/connecting-to-gmail-through-imap-with-php-ssl-context-failed) – Steven V Aug 12 '13 at 16:05
  • Thanks. I had read that one. I just says rebuilt php and openssl and the problem when away. No real reason or solution to the issue. – Haymps Aug 12 '13 at 16:58
  • @StevenV that question you linked is *completely* different... – Sammitch Aug 12 '13 at 17:14
  • Have you verified that port 993 is even available on that host? That is, it's quite possible Amazon (or your image) has firewalled it. – Max Aug 12 '13 at 19:14
  • I am actually getting to Google and they are replying in the error message. Here's the message returned in full (I have logged in as they asked): -Array ( [0] => Retrying PLAIN authentication after [ALERT] Please log in via your web browser: http://support.google.com/mail/accou [1] => Retrying PLAIN authentication after [ALERT] Please log in via your web browser: http://support.google.com/mail/accou [2] => Can not authenticate to IMAP server: [ALERT] Please log in via your web browser: http://support.google.com/mail/accou ) Can't connect to '{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX – Haymps Aug 12 '13 at 21:13
  • Did you log in via your web browser as it says? Google occasionally locks accounts and to unlock them you must log in via a web browser. It is possible Google has identified AWS as a point of abuse. – Max Aug 13 '13 at 01:55
  • 1
    @max thanks. I did login and I cleared the messages, but still couldn't read them. AWS support gave me the solution. I clicked the link (https://accounts.google.com/DisplayUnlockCaptcha) from my PC. It replied that my account was unlocked. Then when I tried the program again from AWS instance, it worked and now I can read gmail emails. This had to be locked from the beginning, but I don't know how my other servers (Netfirms and my PC) were able to read, but not AWS. One person guessed, because it was a new IP address that gmail blocked it right out of the gate. – Haymps Aug 13 '13 at 14:16
  • @haymps, that worked for me too. You should add it as an answer and accept it. – Ian Dunn Dec 06 '13 at 23:23

1 Answers1

4

This fixes it...

I clicked the link (accounts.google.com/DisplayUnlockCaptcha) from my PC. It replied that my account was unlocked. Then when I tried the program again from AWS instance, it worked and now I can read gmail emails. This had to be locked from the beginning, but I don't know how my other servers (Netfirms and my PC) were able to read, but not AWS. One person guessed, because it was a new IP address that gmail blocked it right out of the gate.

Haymps
  • 91
  • 9