Go Back   Web Hosting UK Forums | Linux Windows Dedicated Server and cPanel VPS Hosting Forum > Support > php issues.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-06-2007, 03:14 PM
SBh SBh is offline
Member
 
Join Date: Sep 2007
Posts: 58
Default Can anyone connect to Gmail account using PHP?

I am trying to connect Gmail account using imap_open function of PHP.

I have used the imap_open function like this:

For imap access
imap_open ("{imap.gmail.com:993/imap/ssl}Inbox", "username@gmail.com", "password")

For POP access
imap_open("{pop.gmail.com:995/pop3/ssl}Inbox","username@gmail.com", "pasword")

In both of the cases it failed to connect. So, can anyone tell me how to connect gmail accounts using imap_open function?
Reply With Quote
  #2 (permalink)  
Old 12-06-2007, 03:54 PM
kev woodman's Avatar
Premium Member
 
Join Date: Jul 2006
Location: Newport, Wales, UK.
Posts: 1,494
Default

Off the top of my head Google, Yahoo and implement imapi in a non-standard way. You could try using this library instead (it requires CURL) http://gmail-lite.sourceforge.net/wo...ut/libgmailer/.
__________________
homo sum: humani nil a me alienum puto ... ( just Google it )
Reply With Quote
  #3 (permalink)  
Old 12-06-2007, 03:56 PM
kev woodman's Avatar
Premium Member
 
Join Date: Jul 2006
Location: Newport, Wales, UK.
Posts: 1,494
Default

It looks like phpMailer can do it as well in which case I can definitely recommend using that.
__________________
homo sum: humani nil a me alienum puto ... ( just Google it )
Reply With Quote
  #4 (permalink)  
Old 12-06-2007, 05:05 PM
SBh SBh is offline
Member
 
Join Date: Sep 2007
Posts: 58
Default

Phpmailer, yes i have used it for sending mail using gmail SMTP, it worked fine. But that's not the problem, actually I want to retrieve mails by either POP or IMAP.

And gmail-lite, I will give it a try, but I don't think it will work, because I have used gmail-mobile form the same author, which uses same library, but it didn't work. Still I will give another try to gmail-lite, it might work.

Anyway, thanks for your help.
Reply With Quote
  #5 (permalink)  
Old 12-06-2007, 06:40 PM
kev woodman's Avatar
Premium Member
 
Join Date: Jul 2006
Location: Newport, Wales, UK.
Posts: 1,494
Default

Are you getting a particular error?
__________________
homo sum: humani nil a me alienum puto ... ( just Google it )
Reply With Quote
  #6 (permalink)  
Old 12-06-2007, 06:49 PM
SBh SBh is offline
Member
 
Join Date: Sep 2007
Posts: 58
Default

No, It's just a general error, that it can not connect to the server.

This thing is really strange, that almost every email clients which allow IMAP or POP3 can easily connect to Gmail, then why not PHP? I have searched the net but no one came out with any proper solution.
Reply With Quote
  #7 (permalink)  
Old 12-07-2007, 08:52 AM
kev woodman's Avatar
Premium Member
 
Join Date: Jul 2006
Location: Newport, Wales, UK.
Posts: 1,494
Default

hmm - can you post your code?
__________________
homo sum: humani nil a me alienum puto ... ( just Google it )
Reply With Quote
  #8 (permalink)  
Old 12-07-2007, 10:23 AM
SBh SBh is offline
Member
 
Join Date: Sep 2007
Posts: 58
Default

There is no complex code, the error is at the elementary stage

Code:
$inbox=imap_open ("{imap.gmail.com:993/imap/ssl}Inbox", "username@gmail.com", "password")
 or die("Error: " . imap_last_error());
You execute this code with your IMAP enabled gmail account username, pass. If it fails to connect, error will be shown else nothing.
Reply With Quote
  #9 (permalink)  
Old 12-07-2007, 11:58 AM
new member
 
Join Date: Dec 2007
Posts: 6
Default

this is the code I use on one of my vbulletin forums...its in the form of a block, but the code is solid(even though it could be tidied up a bit lol)

<table border="0" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" class="tborder" width="100%">
<tr>
<td class="tcat"><span class="smallfont"><b>$vba_options[portal_blockbullet]
GMail Login</b></span></td>
</tr>
<tr>
<td class="alt1" style="text-align:center; font-family:arial,sans-serif" nowrap=nowrap>



<div id=login style="font-family: arial,sans-serif">
<script type="text/javascript"><!--



function gaia_setFocus() {
var f = null;
if (document.getElementById) {
f = document.getElementById("gaia_loginform");
} else if (window.gaia_loginform) {
f = window.gaia_loginform;
}
if (f) {
if (f.Email.value == null || f.Email.value == "") {
f.Email.focus();
} else {
f.Passwd.focus();
}
}
}

//--> </script> <div style= id="gaia_loginbox" class="body"> <form action="https://www.google.com/accounts/ServiceLoginAuth" id="gaia_loginform" method="post"> <input type="hidden" name="continue" value="http://gmail.google.com/gmail?ui=html&amp;zy=l"> <input type="hidden" name="service" value="mail"> <table cellpadding="1" cellspacing="0" border="0" id="gaia_table"> <tr>
<td class="alt1" style="font-family: arial,sans-serif">
<font color="#aa1002" style="font-family: arial,sans-serif"> <div class="errorbox-good"> </div> </font> </td> </tr> <tr>
<td class="alt1" nowrap style="font-family: arial,sans-serif" align="center">
&nbsp;<font size="-1" face="Arial, sans-serif" style="font-family: arial,sans-serif">Username</font></td>
</tr> <tr>
<td class="alt1" style="font-family: arial,sans-serif" align="center">
<div align="left" style="font-family: arial,sans-serif"> <input type="text" name="Email" value="" size="18"></div> </td>
</tr> <tr>
<td class="alt1" style="font-family: arial,sans-serif" align="center">
&nbsp;<font size="-1">Password</font></td>
</tr> <tr>
<td class="alt1" style="font-family: arial,sans-serif" align="center">
<div class="alt1" align="left" style="font-family: arial,sans-serif"> <input type="password" name="Passwd" autocomplete="off" size="18"></div> </td>
</tr> <tr>
<td class="alt1" style="font-family: arial,sans-serif" align="center">
<div class="alt1" style="font-family: arial,sans-serif"> <input type="submit" name="null" value="Sign in"> </div> </td> </tr> </table> </form> </div>

</div>

<script>
<!--
if (is_browser_supported) {
var form = el("gaia_loginform");
var url = form["continue"].value;
url = StripParam(url, "ui=html");
url = StripParam(url, "zy=l");
form["continue"].value = url;
}
// -->
</script>



</tr>
</table>
<br/>

Studsy
Reply With Quote
  #10 (permalink)  
Old 12-07-2007, 12:04 PM
kev woodman's Avatar
Premium Member
 
Join Date: Jul 2006
Location: Newport, Wales, UK.
Posts: 1,494
Default

Can you talk us through that? Am I right in thinking this all takes place client side? What output do you end up with? Does it just open the gmail page in the browser or do you do some other processing that I'm missing?
__________________
homo sum: humani nil a me alienum puto ... ( just Google it )
Reply With Quote
  #11 (permalink)  
Old 12-07-2007, 12:25 PM
new member
 
Join Date: Dec 2007
Posts: 6
Default

You end up with a login box on your site. The visitor fills in the form, which then leads them to their inbox page(gmail.com). Hope this helps!

Studsy
Reply With Quote
  #12 (permalink)  
Old 12-07-2007, 12:35 PM
kev woodman's Avatar
Premium Member
 
Join Date: Jul 2006
Location: Newport, Wales, UK.
Posts: 1,494
Default

Afraid not - what SBh is trying to do is open the Gmail inbox as a resource.
__________________
homo sum: humani nil a me alienum puto ... ( just Google it )
Reply With Quote
  #13 (permalink)  
Old 12-07-2007, 01:07 PM
kev woodman's Avatar
Premium Member
 
Join Date: Jul 2006
Location: Newport, Wales, UK.
Posts: 1,494
Default

Just a thought but have you tried it without the SSL tag?
__________________
homo sum: humani nil a me alienum puto ... ( just Google it )
Reply With Quote
  #14 (permalink)  
Old 12-07-2007, 06:31 PM
SBh SBh is offline
Member
 
Join Date: Sep 2007
Posts: 58
Default

@studsy: This was not my problem, but still this type of login system is interesting. However did you try this type of login with Google Apps accounts, I failed to create such separate login forms for google apps accounts.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 04:01 AM.
Copyright 2002-2007 WebHosting.uk.com. All rights reserved.
Web Hosting UK Forum