Monwabisi Posted August 14, 2013 Share Posted August 14, 2013 Hi, I am trying to retrieve eMail messages from a google account using imap, it works well on localhost but when pushing the code to a remote server, it returns: Can not authenticate to IMAP server: [AUTHENTICATIONFAILED] Invalid credentials (Failure). Can anyone please tell me what the solution to this problem is? Quote Link to comment https://forums.phpfreaks.com/topic/281173-php-imap-returning-authantication-error-on-remote-server-but-connects-on-localhost/ Share on other sites More sharing options...
jazzman1 Posted August 14, 2013 Share Posted August 14, 2013 IMAP is a library. Are sure that your hosting provides you by default? Quote Link to comment https://forums.phpfreaks.com/topic/281173-php-imap-returning-authantication-error-on-remote-server-but-connects-on-localhost/#findComment-1445054 Share on other sites More sharing options...
Monwabisi Posted August 14, 2013 Author Share Posted August 14, 2013 Well, I am using a class that extends imap, here is the code: function __construct($emailHost, $emailPort, $emailOptions, $emailLogin, $emailPassword) { $hostString = "{{$emailHost}:{$emailPort}/{$emailOptions}}"; $this->mbox = imap_open($hostString, $emailLogin, $emailPassword, OP_SILENT) or die("can't connect: " . imap_last_error()); // Remove all mail that may have been marked for deletion // via another process, E.g script that died imap_expunge($this->mbox); $this->connected = TRUE; } I use ubuntu on my local machine and on the cloud server, the same login credentials are used on local machine and on the remote server to login to the Gmail account I want to pull email messages from. Quote Link to comment https://forums.phpfreaks.com/topic/281173-php-imap-returning-authantication-error-on-remote-server-but-connects-on-localhost/#findComment-1445059 Share on other sites More sharing options...
jazzman1 Posted August 14, 2013 Share Posted August 14, 2013 (edited) Ah...now I see! You got a message from imap_last_error() right? So, if everything is OK about the username and the password, you should check inside google mail box from a message with a title - Suspicious sign in prevented! Make the server ip address to be a trust by google. That's all you can do. Never had an experiance with IMAP in php, but often use openssl in bash and I think this cause the problem. Edited August 14, 2013 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/281173-php-imap-returning-authantication-error-on-remote-server-but-connects-on-localhost/#findComment-1445066 Share on other sites More sharing options...
Monwabisi Posted August 14, 2013 Author Share Posted August 14, 2013 Sounds like it could work, how do I do that? the account which I pull the emails from is a gmail account . (FYI) Quote Link to comment https://forums.phpfreaks.com/topic/281173-php-imap-returning-authantication-error-on-remote-server-but-connects-on-localhost/#findComment-1445069 Share on other sites More sharing options...
jazzman1 Posted August 14, 2013 Share Posted August 14, 2013 (edited) I already told you how Open up your browser and login into your gmail account. Then check for a message with that title -Suspicious sign in prevented, and follow the steps making the server ip to have an access to your google account. Edited August 14, 2013 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/281173-php-imap-returning-authantication-error-on-remote-server-but-connects-on-localhost/#findComment-1445073 Share on other sites More sharing options...
Monwabisi Posted August 15, 2013 Author Share Posted August 15, 2013 There isn't any, there is no message with Suspicious sign. Quote Link to comment https://forums.phpfreaks.com/topic/281173-php-imap-returning-authantication-error-on-remote-server-but-connects-on-localhost/#findComment-1445116 Share on other sites More sharing options...
jazzman1 Posted August 15, 2013 Share Posted August 15, 2013 First, check whether openssl is alredy installed on the machine. Open up a ssh connection, go to the server terminal and try to login into your Google account. So, the command is: openssl s_client -crlf -connect imap.gmail.com:993 // next command TAG1 LOGIN accountName accountPassword // exit TAG1 LOGOUT If you recieve some error message, let's see it. If everything is ok, try to run next script by php: <?php $mbox = imap_open ('{imap.gmail.com:993/ssl/novalidate-cert}[Gmail]/All Mail', 'accountName@gmail.com', "accountPassword") or die("can't connect: " . imap_last_error()); echo "<h1>Mailboxes</h1>\n"; $folders = imap_listmailbox($mbox, "{imap.gmail.com:993}", "*"); if ($folders == false) { echo "Call failed<br />\n"; } else { foreach ($folders as $val) { echo $val . "<br />\n"; } } echo "<h1>Headers in INBOX</h1>\n"; $headers = imap_headers($mbox); if ($headers == false) { echo "Call failed<br />\n"; } else { foreach ($headers as $val) { echo $val . "<br />\n"; } } imap_close($mbox); Quote Link to comment https://forums.phpfreaks.com/topic/281173-php-imap-returning-authantication-error-on-remote-server-but-connects-on-localhost/#findComment-1445150 Share on other sites More sharing options...
Monwabisi Posted August 15, 2013 Author Share Posted August 15, 2013 (edited) When using the first attempt, this is the error message I am getting: TAG1 NO [AUTHENTICATIONFAILED] Invalid credentials (Failure) THANKS A LOT FOR THE EFFORT MAN, I REALLY DO NOT KNOW WHAT TO DO AT THIS POINT Edited August 15, 2013 by Monwabisi Quote Link to comment https://forums.phpfreaks.com/topic/281173-php-imap-returning-authantication-error-on-remote-server-but-connects-on-localhost/#findComment-1445216 Share on other sites More sharing options...
jazzman1 Posted August 15, 2013 Share Posted August 15, 2013 When using the first attempt, this is the error message I am getting: TAG1 NO [AUTHENTICATIONFAILED] Invalid credentials (Failure) THANKS A LOT FOR THE EFFORT MAN, I REALLY DO NOT KNOW WHAT TO DO AT THIS POINT Now, open up your browser again, login into your google account and check for a message with a title - Suspicious sign in prevented. Double check accountName and password. You are doing something wrong I'm pretty sure. Did you try to run openssl from your local server? Quote Link to comment https://forums.phpfreaks.com/topic/281173-php-imap-returning-authantication-error-on-remote-server-but-connects-on-localhost/#findComment-1445220 Share on other sites More sharing options...
Monwabisi Posted August 15, 2013 Author Share Posted August 15, 2013 (edited) Did you try to run openssl from your local server? Yes, and this is the message I get: TAG1 OK example@domain.com display_name authenticated (Success) Edited August 15, 2013 by Monwabisi Quote Link to comment https://forums.phpfreaks.com/topic/281173-php-imap-returning-authantication-error-on-remote-server-but-connects-on-localhost/#findComment-1445222 Share on other sites More sharing options...
Monwabisi Posted August 15, 2013 Author Share Posted August 15, 2013 (edited) Double check accountName and password. You are doing something wrong I'm pretty sure. I copy and paste the credentials for both localhost and remote server. Do you think I should call google when I get to work tomorrow? Edited August 15, 2013 by Monwabisi Quote Link to comment https://forums.phpfreaks.com/topic/281173-php-imap-returning-authantication-error-on-remote-server-but-connects-on-localhost/#findComment-1445223 Share on other sites More sharing options...
jazzman1 Posted August 15, 2013 Share Posted August 15, 2013 That's good. Does the username and the password contain non-english characters? Did you check inside google mail box for that messge above? Quote Link to comment https://forums.phpfreaks.com/topic/281173-php-imap-returning-authantication-error-on-remote-server-but-connects-on-localhost/#findComment-1445224 Share on other sites More sharing options...
Monwabisi Posted August 15, 2013 Author Share Posted August 15, 2013 Yes there are non-english characters, and I checked the gmail account but there aren't any messages with suspicious symbol. Quote Link to comment https://forums.phpfreaks.com/topic/281173-php-imap-returning-authantication-error-on-remote-server-but-connects-on-localhost/#findComment-1445226 Share on other sites More sharing options...
jazzman1 Posted August 15, 2013 Share Posted August 15, 2013 Yes there are non-english characters, and I checked the gmail account but there aren't any messages with suspicious symbol. Yes, that's the problem the non-english characters. What encoding charset are you using inside console? Quote Link to comment https://forums.phpfreaks.com/topic/281173-php-imap-returning-authantication-error-on-remote-server-but-connects-on-localhost/#findComment-1445228 Share on other sites More sharing options...
Monwabisi Posted August 15, 2013 Author Share Posted August 15, 2013 (edited) thanks man, thank you very much, thank you, would love to follow you on twitter or Gplus. Edited August 15, 2013 by Monwabisi Quote Link to comment https://forums.phpfreaks.com/topic/281173-php-imap-returning-authantication-error-on-remote-server-but-connects-on-localhost/#findComment-1445229 Share on other sites More sharing options...
jazzman1 Posted August 15, 2013 Share Posted August 15, 2013 Now, you know where the problem is. I don't have a too much time now for explanations. Quote Link to comment https://forums.phpfreaks.com/topic/281173-php-imap-returning-authantication-error-on-remote-server-but-connects-on-localhost/#findComment-1445231 Share on other sites More sharing options...
Monwabisi Posted August 15, 2013 Author Share Posted August 15, 2013 (edited) OHK, I removed all the NON English characters, but same error message, seems I counted the chickens a bit too soon, or am I missing something? Edited August 15, 2013 by Monwabisi Quote Link to comment https://forums.phpfreaks.com/topic/281173-php-imap-returning-authantication-error-on-remote-server-but-connects-on-localhost/#findComment-1445234 Share on other sites More sharing options...
jazzman1 Posted August 15, 2013 Share Posted August 15, 2013 (edited) Ok, try to connect to my testing google account. Open up the terminal to your remote server and type: openssl s_client -crlf -connect imap.gmail.com:993 // next TAG LOGIN tuparov86@gmail.com Canada2011+ If everything is OK, I shoud have receive a message from google that someone recently tried to use an application to sign in to my mail Google Account. Edited August 15, 2013 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/281173-php-imap-returning-authantication-error-on-remote-server-but-connects-on-localhost/#findComment-1445237 Share on other sites More sharing options...
Monwabisi Posted August 15, 2013 Author Share Posted August 15, 2013 (edited) Ok, try to connect to my testing google account. TAG NO [ALERT] Please log in via your web browser Edited August 15, 2013 by Monwabisi Quote Link to comment https://forums.phpfreaks.com/topic/281173-php-imap-returning-authantication-error-on-remote-server-but-connects-on-localhost/#findComment-1445239 Share on other sites More sharing options...
jazzman1 Posted August 15, 2013 Share Posted August 15, 2013 TAG NO [ALERT] Please log in via your web browser Yes, I got a message from google: Hi Dimitar, Someone recently tried to use an application to sign in to your Google Account - tuparov86@gmail.com. We prevented the sign-in attempt in case this was a hijacker trying to access your account. Please review the details of the sign-in attempt: Thursday, August 15, 2013 8:12:00 PM UTC IP Address: 192.34.57.169 Location: Tehrān, Iran If you do not recognize this sign-in attempt, someone else might be trying to access your account. You should sign in to your account and reset your password immediately. Quote Link to comment https://forums.phpfreaks.com/topic/281173-php-imap-returning-authantication-error-on-remote-server-but-connects-on-localhost/#findComment-1445240 Share on other sites More sharing options...
jazzman1 Posted August 15, 2013 Share Posted August 15, 2013 As I said before, you are doing something wrong and only you knoq what is it Quote Link to comment https://forums.phpfreaks.com/topic/281173-php-imap-returning-authantication-error-on-remote-server-but-connects-on-localhost/#findComment-1445241 Share on other sites More sharing options...
Monwabisi Posted August 15, 2013 Author Share Posted August 15, 2013 Well that makes me feel very clever, but if that is the case then I shall work it out, thanks for everything, I would have never got this close to it if it was not for you, now I have a bit more understanding of how things work, (I also learned openssl from all of this) I feel like a geek in the making. I will find out what it is that I am doing wrong and then inform you so to close out the topic. million thanks Quote Link to comment https://forums.phpfreaks.com/topic/281173-php-imap-returning-authantication-error-on-remote-server-but-connects-on-localhost/#findComment-1445243 Share on other sites More sharing options...
Monwabisi Posted August 19, 2013 Author Share Posted August 19, 2013 I honestly think it has something to do with google, I think this can never be solved. Quote Link to comment https://forums.phpfreaks.com/topic/281173-php-imap-returning-authantication-error-on-remote-server-but-connects-on-localhost/#findComment-1445753 Share on other sites More sharing options...
jazzman1 Posted August 19, 2013 Share Posted August 19, 2013 I honestly think it has something to do with google, I think this can never be solved. What's the problem now? You still don't have an access to your gmail account or what? Quote Link to comment https://forums.phpfreaks.com/topic/281173-php-imap-returning-authantication-error-on-remote-server-but-connects-on-localhost/#findComment-1445840 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.