Retrieve Your Gmail Emails Using PHP and IMAP

Gmail

Grabbing emails from your Gmail account using PHP is probably easier than you think. Armed with PHP and its IMAP extension, you can retrieve emails from your Gmail account in no time! Just for fun, I'll be using the MooTools Fx.Accordion plugin to display each email.

The CSS

div.toggler				{ border:1px solid #ccc; background:url(gmail2.jpg) 10px 12px #eee no-repeat; cursor:pointer; padding:10px 32px; }
div.toggler .subject	{ font-weight:bold; }
div.read					{ color:#666; }
div.toggler .from, div.toggler .date { font-style:italic; font-size:11px; }
div.body					{ padding:10px 20px; }

Some simple CSS formatting.

The MooTools JavaScript

window.addEvent('domready',function() {
	var togglers = $$('div.toggler');
	if(togglers.length) var gmail = new Fx.Accordion(togglers,$$('div.body'));
	togglers.addEvent('click',function() { this.addClass('read').removeClass('unread'); });
	togglers[0].fireEvent('click'); //first one starts out read
});

Some simple accordion code.

The PHP

/* connect to gmail */
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'davidwalshblog@gmail.com';
$password = 'davidwalsh';

/* try to connect */
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());

/* grab emails */
$emails = imap_search($inbox,'ALL');

/* if emails are returned, cycle through each... */
if($emails) {
	
	/* begin output var */
	$output = '';
	
	/* put the newest emails on top */
	rsort($emails);
	
	/* for every email... */
	foreach($emails as $email_number) {
		
		/* get information specific to this email */
		$overview = imap_fetch_overview($inbox,$email_number,0);
		$message = imap_fetchbody($inbox,$email_number,2);
		
		/* output the email header information */
		$output.= '<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">';
		$output.= '<span class="subject">'.$overview[0]->subject.'</span> ';
		$output.= '<span class="from">'.$overview[0]->from.'</span>';
		$output.= '<span class="date">on '.$overview[0]->date.'</span>';
		$output.= '</div>';
		
		/* output the email body */
		$output.= '<div class="body">'.$message.'</div>';
	}
	
	echo $output;
} 

/* close the connection */
imap_close($inbox);

With our individual username/password settings set, we connect to Gmail. Once connected, we request all emails. If we find emails, I reverse sort the emails so that the newest emails appear on top. For every email we receive, I output the subject and message in MooTools Fx.Accordion format.

Now that I've shown you the basics, it's time for you to build your next great PHP email app! Go ahead and send a few emails to davidwalshblog@gmail.com to see your eamil display on the page!

There are some encoding issues and I've not found a great way to include images. Any tips appreciated!


Comments

  1. Myfacefriends

    great and useful many thanks David!

  2. kburn

    nice shot Dave!

  3. Ahmed

    I love it. Wish I could mark emails as read when you toggle them though.
    Oh, and I noticed a flicker when toggling “unread” emails.

  4. Ahmed

    NVM the flicker thing, guess it was my FF acting weird :P

  5. Adriaan

    Your picture is outdated…gmail is out of beta ;)

  6. David Walsh

    I did that on purpose. Always beta!
    O

    • valene henderson

      could you help me get into my account, i forgot the password i would greatly appreciate it. i listed my gmail address(vh7780@gmail.com
      )

  7. Adriaan

    how can one get a list of contacts of a gmail account? Facebook and most social networking sites do that…but how?

  8. Devang Paliwal

    Awesome post. Can we do it for other emails ie Yahoo, Hotmail etc.

  9. scvinodkumar

    wow this is great code. Congratulations…

    how to display new mails only?

  10. Rob Simpkins

    @scvinodkumar – The method imap_fetch_overview() returns an array, one parameter of which is called ‘seen’. This flag indicates whether the message has been read or not. Likewise you have ‘answered’, whether you’ve replied to the message.

    Good post David, thank you.

  11. David Walsh

    @Devang Paliwal: Absolutely! You’d need to get each service’s IMAP information though.

  12. Zeus

    Is it secure? Could this be implemented with accounts contain personal and confidential mails?

  13. David Walsh

    @Zues: How you use this is up to you. I don’t recommend making your primary email account public.

  14. zeus

    Hmmm okay. But this is something great. Can brainstorm and come up with new and cool ideas :)

  15. Soso

    Fatal error: Call to undefined
    function imap_open() in
    C:\wamp\www\New folder\index.php on
    line 13

    Can someone help ?

  16. scvinodkumar

    @soso: please enable “extension=php_imap.dll” in php.ini

  17. stephex

    I want get attachment de Gmail. How? Thanks.

  18. chris

    Hey this looks awesome!
    I tried to use it with wamp and am getting this error…any ideas? Thanks a lot for any help!!

    Warning: imap_open() [function.imap-open]: Couldn’t open stream {imap.gmail.com:993/imap/ssl}INBOX in C:\wamp\www\email\howdy.php on line 13
    Cannot connect to Gmail: Can’t open mailbox {imap.gmail.com:993/imap/ssl}INBOX: invalid remote specification

  19. David Walsh

    @chris: Not sure, could be an outbound connection or firewall issue. “Localhost” always bring trouble.

  20. chris

    Thanks David, you were correct it was a firewall issue that blocked 993.

  21. kodegeek

    is this works for inline attachments such as picture added inside the text through outlook express?
    Great stuff!

  22. Iván

    Q? Why I get this error : Cannot connect to Gmail: Can’t open mailbox {imap.gmail.com:993/imap/ssl}INBOX: invalid remote specification

  23. chris

    @Iván: I had this same error, it’s your firewall settings blocking 993 port. When you unblock it, it works.

  24. Iván

    I´ve fixed my problem.

    Thank You Chris.

  25. Stylianos

    Thank you so much you are genius!!!

  26. nimz

    great idea,
    demo is down though, “Cannot connect to Gmail: Too many login failures”

  27. David Walsh

    @nimz: Ah, a Chelsea boy. Nice. Since I posted the article the accounts been hacked at. I’ll see if I can restore it.

  28. Varun Kumar Sen

    Cannot connect to Gmail: Can’t open mailbox {imap.gmail.com:993/imap/ssl}INBOX: invalid remote specification – this error i get, when i run this code in localhost means local system..

  29. el santo!

    dude.. awesome job.. but im unsing latin characters and i got ugly formed emails.. there is any parameter for change the charset?

  30. Ben

    This doesn’t work for me for some reason. I’m running it locally on Wamp, and I turned the firewall off… I can get the email subjects but when I click on them they don’t do anything.

  31. Dextor

    maybe Im missing something but I could not find a download link to download this amazing script.

    I downloaded the mootools.js file into a dir on my cpanel server. Then created a new file and think I put the above codes into the right place etc but when i try to load the page,it just sits there saying loading in the status bar, nothing happens, been waiting 9 minutes without error message.

    any ideas please or am i missing a download link to download all files needed.

    cheers

    Dextor

  32. David Walsh

    Dextor: All of the necessary code is here. I’m guessing that your machine is having a problem connecting to GMail, or GMail is slow. The fact that it tries for a while instead of just dying means it’s attempting to get to Gmail. You may also want to change your username and password.

  33. Dextor

    wow quick response, thanks David, can i pastbin my file so you can see if i have it setup right?

  34. Dextor

    here is the pastebin.ca link

    http://pastebin.ca/1570904

  35. David Walsh

    @Dextor: You need to make your code a complete page with ,, etc. I also don’t see you bringing in the MooTools library.

  36. Dextor

    This look better?

    dreamweaver code color says the css / mootools part looks odd / wrong color like the syntax is out of place / incorrect

    http://pastebin.ca/1570922

  37. Gordie

    I get this error….

    Cannot connect to imap: Certificate failure for imap.gmail.com: unable to get local issuer certificate: /C=US/O=Google Inc/CN=Google Internet Authority

    • abdullah

      change

      {imap.gmail.com:993/ssl}

      to

      {imap.gmail.com:993/ssl/novalidate-cert}

  38. Noe Rodriguez

    How to solve the encoding problem’s???

    Thank’s if you have an answer!

  39. Bob Snider

    I get a bunch of garbage that looks like a SSL certificate after the first message and the body does not print on remaining emails. Any ideas?

    –1248921015.4E4FF544.18054 Date: Wed, 29 Jul 2009 19:30:15 -0700 MIME-Version: 1.0 Content-Type: image/gif Content-Transfer-Encoding: base64 Content-Disposition: inline; filename=”email-vox-logo.gif” Content-ID: R0lGODlhawAtAOYAANcZIP////fR0v/8/Od1edgeJdopMPO7vd05P/309f739/GusONdYtccI/nf 4P76+uqFidkkKvzv79ghKPrk5dw0OvK2uNknLfjW2N9HTd5CR/fU1dsxOOd4fPvn5++go+Vqb+Nf ZN9ESvbJy/3x8uBPVNosMuyTluFVWuh6fuJaX9w3PfCoq+yQk/zs7d08Qudyd+6bnuVnbPXGyO+m qPvp6tsvNfrh4vXDxfTBw+RlaeFSV+ZtcemDhvfO0OBMUuuMj+h9geuNkeuLjt9KT/bMzeqIjPnc 3emAhO2Ym/CrrvjZ2uRiZ+2VmfO5u++jpt4/RfS+wPGxs+ZwdPKztuJXXO6eoQAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5 BAAAAAAALAAAAABrAC0AAAf/gAGCg4QSAocJhIqDR4cbi5CCjYcCD5GQFI6XhJQem5+KAkgVAKWl L0Y3igMLIRGmAAUMT5aKChYpIrCmJiEnGJFOIBe7VTGJhCRNO7sGIFGglzcgu7sFHSSCTi/VsBVK gxswxN3VGR8KgyNE5aUGMYIDJ+TlPwLRijMG7bAIS0j8YMFYwiNgORs0AsRoYBAAAwooGhZ4gk9b gYYYMza0obFjC3wY6HUcSbIkRgugBugyybKlSwARPG2i8XKkiQw6CMDIgKDmyA6fNHRTIqDIkIwZ LByC0s4EhBmQHLQQGtBAEQE5mPErceCQinIT0pkCAiAAACAUyhkZFALjowBp/7tFEIJsk5IVAU8I ItGznAkJgjYwLHdAUNkMZwFkoNntxaAFDR0LatKNCAVILiA9mMIvpqAD7RbEW1kuhWGzZMn2aPeW xASDEAYh3qUjnaAHVHSYMDVBRYzMgxa2AzGIQbcSgz4ERHG6rHMY7WILMh7QhyAH1UIMGCSlr9wW tgMob1fk+kVYBRwIkrCPX4ZLKdqtGMS4XYVBLXZpQDYgvkEiNQwSRDvICSLELtIFUFBAP1ySXzvW BSDBYOUEMQhVpTQAjCAyZIQAYAE8gFc5ooXoHQK1jNCQDpdYwE8Pg2hVzgiCYLALAYMk0ZEK2wUA WTkcIANaKYUFoFJDQ1ySwP9r5dwnyHjdmNCjEejJ5MF5GrEwCGnVJGgccYLo2BCNl3RIniBxdQOU IN4BwMQgBJCEQI9WtJPedQZY+YpBUHyCAZbVWChICYQJIsAuJS5ZEg5o8hPCIJcJQk1DJW5yYJM9 ntCNAT2uBot6AQxJEoyCjDijIjhg9GZKhJ4awBHdgBkAKbzhZ5IKg3zVjgg9mtgQB8CBkkBE3Zgm CIamFKmiN4N0YFKfgizYDkqCsNAQApHiowCtu9jQIwS7hCWIf6YgAKdJ8wkSZztBDsJeQAWoUtED TLQDVQA2wiJDPBzBYoOAJr3HIT9UKALlrgFGM0AV/Kw5KywlprpLA7XUN9L/voL80A4Dg/Q4ALLl vBDsJkfxw6kgAJUyQTYBrLvLW/mS9MEgIqEHKgkM9Ciqo6A4AGg5OQiyrEPxtLdLExeSVEDCMXfZ LAAzT9dQwZukHBCORranZajlEMEdSQ6D2027AQgGgAEg+myQCJs8sJtBJwfgbAMgSlvNPRl3dEHC CvRbDbUBtApA2A1tCEkUGRUJGnMBKFAzLByj+XZDDRQZgJjVRO4jLA0cIUgCHBikVyQPNjSFIAoY ELWL/DgxiA9G89MARWjuaQ2ooO+i+Y/8YAwJuXDbxkOkZrZzgeE3cBll0KiDbEqCYu9i+WwEXuJy Q0WCqgCT/CAwMg2mwnKB/xEsG9nW2MiYXQ2KQgckMCQDZiSrILwHhACogwjQBAH8DxFFrwFIgK66 ATjBVWN0AZhUORgHiYMZ5ALhCcD5GhKBDwBwEzgIn+4e0xk9tQNrkGhaQwAnAe5hBAGVikQRiFWO OwUwdPyAwSA0RaJNcCMjGuAfAagzkgvogAUCeMQNBIALGPKjAjpkYTsaAAP+caYbEwBRJJ7gkypa sWGfGABTrsjFK0YgYZvwgQm7SEaWbA0U9SvjSGx3xQRF4wBstM8MoNOQEGSFJBdIggKiF5Ad+IAd DUFgRZYwwHIwIWFKMOKm4CGIHDCAQgFZgRCkaIE2VWMu23kABMaoH0ZVJGAfIIgdAGxAALwNQgFW UGIpfnCC8g3CBTHQAbfQU4Ie3EsRD6CBCiAJAA0MQYqCqIERbmiKAoQghZ9cxCGAuIRPGCIKXRnZ JTywzBwcAh8kEAAOlJKtSAxRCjMQQF0qEggAOw== –1248921015.4E4FF544.18054 Date: Wed, 29 Jul 2009 19:30:15 -0700 MIME-Version: 1.0 Content-Type: image/gif Content-Transfer-Encoding: base64 Content-Disposition: inline; filename=”spacer.gif” Content-ID: R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw== –1248921015.4E4FF544.18054–

  40. Noe Rodriguez

    Bob Snider : If the email has an attachment you will see that. The code in this place is just an idea to make a better code. Check the Imap functions at php.net . I’m still working in this, the idea is good but not complete.

  41. kushal

    hi this is superb script…

    but i got some errors

    Warning: imap_open() [function.imap-open]: Couldn’t open stream {imap.gmail.com:993/imap/ssl}INBOX in /home/ospreyan/public_html/kushal/mail.php on line 8
    Cannot connect to Gmail: Can’t connect to gmail-imap.l.google.com,993: Connection refused

    can you help me in that

  42. deepak

    i used ur exact code. there is no error but half of the code is printed instead of the emails.
    here is the code i took from u exactly. try to run it with ur username and password. does it run correct. change the username and password. thanks anybody.

    <?
    /* connect to gmail */
    $hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
    $username = 'yourusername@gmail.com';
    $password = 'yourpassword';
    /* try to connect */
    $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to

    Gmail: ' . imap_last_error());
    /* grab emails */
    $emails = imap_search($inbox,'ALL');
    /* if emails are returned, cycle through each… */
    if($emails) {
    /* begin output var */
    $output = '';
    /* put the newest emails on top */
    rsort($emails);
    print_r($emails);
    /* for every email… */
    foreach($emails as $email_number) {
    /* get information specific to this email */
    $overview = imap_fetch_overview($inbox,$email_number,0);
    $message = imap_fetchbody($inbox,$email_number,2);
    /* output the email header information */
    $output.= 'seen ? “read” : “unread”).’”>’;
    $output.= ”.$overview[0]->subject.’ ‘;
    $output.= ”.$overview[0]->from.”;
    $output.= ‘on ‘.$overview[0]->date.”;
    $output.= ”;
    /* output the email body */
    $output.= ”.$message.”;
    }
    echo $output;
    }
    /* close the connection */
    imap_close($inbox);
    ?>

  43. @MikeKorcha

    If you are getting a lot of weird characters in the message body (i.e. =0D or =0A) then you have to check the encoding with imap_fetchstructure() and then decode it properly. You only need to decode for Quoted-Printable and Base64, however. Here is my code for this:

    $structure = imap_fetchstructure($mailbox, $uid, FT_UID);
    if($structure->encoding == “3″){
    $body = base64_decode(imap_fetchbody($mailbox, imap_msgno($mailbox, $uid), 1));
    }
    elseif($structure->encoding == “4″){
    $body = imap_qprint(imap_fetchbody($mailbox, imap_msgno($mailbox, $uid), 1));
    }else{
    $body = imap_fetchbody($mailbox, imap_msgno($mailbox, $uid), 1);
    }

    Note that I use UIDs, so this will have to be changed for however you are doing it.

  44. Swati

    @deepak: Fatal error: Call to undefined function imap_open() in C:\wamp\www\swaticlass\imapp.php
    Im geeting this errior could nyone solve it

  45. Andrea

    Cery cool script !!! But I notice that is very very slow to load. Why ?

  46. chris

    Hi dave, I tried your exact code, but the javascript didn’t work. I’m using firefox 3.0.14 – php5 – apache2. All the email body (the messages) are all listed before i have to click the email subject. Any suggestion?

    This is my phpcode:
    <?php
    $formatcss = "

    “;
    echo $formatcss;

    $javascript = ”
    window.addEvent(‘domready’,function() {
    var togglers = $$(‘div.toggler’);
    if(togglers.length) var gmail = new Fx.Accordion(togglers,$$(‘div.body’));
    togglers.addEvent(‘click’,function() { this.addClass(‘read’).removeClass(‘unread’); });
    togglers[0].fireEvent(‘click’); //first one starts out read
    });
    “;
    echo $javascript;

    /* connect to gmail */
    $hostname = ‘{imap.gmail.com:993/imap/ssl}INBOX’;
    $username = ‘username@gmail.com’;
    $password = ‘password’;

    /* try to connect */
    $inbox = imap_open($hostname,$username,$password) or die(‘Cannot connect to Gmail: ‘ . imap_last_error());

    /* grab emails */
    $emails = imap_search($inbox,’ALL’);

    /* if emails are returned, cycle through each… */
    if($emails) {

    /* begin output var */
    $output = ”;

    /* put the newest emails on top */
    rsort($emails);

    /* for every email… */
    foreach($emails as $email_number) {

    /* get information specific to this email */
    $overview = imap_fetch_overview($inbox,$email_number,0);
    $message = imap_fetchbody($inbox,$email_number,2);

    /* output the email header information */
    $output.= ‘seen ? ‘read’ : ‘unread’).’”>’;
    $output.= ”.$overview[0]->subject.’ ‘;
    $output.= ”.$overview[0]->from.”;
    $output.= ‘on ‘.$overview[0]->date.”;
    $output.= ”;

    /* output the email body */
    $output.= ”.$message.”;
    }

    echo $output;
    }

    /* close the connection */
    imap_close($inbox);
    ?>

    thanks

  47. eicky

    hi,
    I got this error..Call to undefined function imap_open()
    I enabled “extension=php_imap.dll” in php.ini
    stil I have the same problem

  48. novadash

    @chris: how to blocked the 993 port on win xp…i had been added the port on exception, but still not working…
    thanks…!!

  49. novadash

    @David Walsh: one more…
    i used wamp on my server with localhost,…
    and the error is stil “couldn’t not open stream”…
    my server spec is : php. 5.2 and apache 2
    if i replaced the php_imap.dll with the new one from php.5.3..the error is “Call to undefined function imap_open()”..even the php_imap extension is still enable on php.ini..
    can u explain how to setting the php.ini or the firewall setup…please mail me…ty..

  50. kushal

    hi this is superb script…

    but i got some errors

    Warning: imap_open() [function.imap-open]: Couldn’t open stream {imap.gmail.com:993/imap/ssl}INBOX in /home/ospreyan/public_html/kushal/mail.php on line 8
    Cannot connect to Gmail: Can’t connect to gmail-imap.l.google.com,993: Connection refused

    can you help me in that

  51. @MikeKorcha

    If you are using localhost and having problems, look into XAMPP instead of WAMP

  52. saif

    this is very good idea…..

  53. saif

    Can you help me to take the html code of each mail….. and also need to display only the unreaded messages ….. please help me sir…..

  54. Dan Eskildsen

    It doesn’t seem to work with Danish characters, any suggestions?

  55. senthil

    its working well for me .. i m using this with my own server not with gmail. thanks for this great effort…..

  56. Axel

    great, thank you!

  57. Jegan

    hi david,

    can we use jquery instead of using mootools javascript.

    • WpFollow

      jQuery(document).ready(function($){

      var allPanels = jQuery(‘.body’).hide();

      jQuery(‘div.toggler’).click(function() {
      allPanels.slideUp();
      jQuery(this).next().stop().slideToggle();
      return false;
      });
      });

  58. marvinstefani

    if u have problem with certificate, add /novalidate-cert
    imap.gmail.com:993/imap/ssl/novalidate-cert

    if you cant connect then its the port 993 which is blocked (outbound blocking)

    i have great ideas to use this, muahahahaaha(evil laughter)

  59. HDF_1986

    Warning: imap_open() [function.imap-open]: Couldn’t open stream {imap.gmail.com:993/imap/ssl}INBOX in \\hmfsw\web\dtcwin071\6700.com.ar\public_html\ver\mail.php on line 8
    Cannot connect to Gmail: Can’t connect to gmail-imap.l.google.com,993: Host unreachable the php say’s that, i be read about this and say’s “993 port is locked by firewall” what i can do?

  60. old guy

    @deepak: your PHP implementation probably requires <?php, not just <? on the first line

  61. old guy

    @Bob Snider: Its an atachment – you need to read up on mime and how to parse email

  62. elguapo

    david, amazing! can it retrieve also the sent mails? or even user generated folders? i will be studying this IMAP thing.. thanks for the great idea! feed on!

  63. StubleU

    @David Walsh: i seem to be having the same problem as nimz where i’m getting “Cannot connect to Gmail: Too many login failures” even though my accounts are perfectly fine?

  64. Igor

    Thank you, David, very useful stuff.
    Something strange in folder structure, where does Google store spam…

  65. Yogesh Tank

    Hi David,

    Just wanted to know if we could also acquire the attachments with the email as well.

    If this is possible please let me know..

    In advance,

    Thanks for your help..

  66. mango

    hey david can you please post the whole script here at your blog, because i think your codes are incomplete and i cannot see sliding animation in my page…

    Thanks

  67. Awais

    Wel the script is 100% working, but i want to know how to paginate the inbox to multiple pages, can anybody tell me?

  68. Boolean Value

    Interesting technique, and I like how you included the accordian to make things more interesting.

    Do we really need another PHP mail app though? :) Integration possibilities are endless though of course.

  69. Craig

    Excellent lesson. I have a question. Im using it to retreive an overview of my gmail into my private intranet. Works great but I would like to make every subject link back to the gmail account directly.. i know i need to get some kind of ID for each mail then redirect to mail.google.com/#inbox or something.. any ideas?

  70. Syed Sumair Zafar

    Thanks david really helpfull

  71. Prashant

    @Iván: Ivan its prob with your config file…go to php.ini and enable (extension_imap blah blah)…and you are done…

  72. Potherca

    Hi,
    First of: Great code example, gets a man up and running in no time! Big thanks.
    Second: have you been folowing the release of gMail IMAP + oAuth?
    That opens the door to all sorts of weird and wonderful opertunities… anything from “Open your gmail from my website” to a Gmail Facebook Tab (because, lets be honest, the current implementations suck :-)

    greetz,
    P.

  73. Dan

    I saved the php code in a TextWrangler document and uploaded it, but on my localhost (MAMP with an IMAP code edit) that delivers a blank page and on x10hosting, I get the following:

    Parse error: syntax error, unexpected $end in /home/r5radar/public_html/walsh.php on line 70

    (I have a thorough understanding of HTML, have some experience with XML, and am just learning php)

    How should the accordion, CSS and php codes be saved? I just want to get this awesome code to work before I embed it in an actual page or design…

  74. gaurab

    @eicky: i think you need to copy the dll into your php directory as well…

  75. Dan

    Alright I think I have the ssl and firewall issues solved (I’m on a mac), but I’ve come to an unexpected T_STRING error on line 55 I can’t see. Here’s my code:

    Gmail to RSS test

    window.addEvent(‘domready’,function() {
    var togglers = $$(‘div.toggler’);
    if(togglers.length) var gmail = new Fx.Accordion(togglers,$$(‘div.body’));
    togglers.addEvent(‘click’,function() { this.addClass(‘read’).removeClass(‘unread’); });
    togglers[0].fireEvent(‘click’); //first one starts out read
    });

    <?php
    $formatcss = "

    ";
    echo $formatcss;

    /* connect to gmail */
    $hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
    $username = 'route5radarproxy@gmail.com';
    $password = 'gothrough';

    /* try to connect */
    $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());

    /* grab emails */
    $emails = imap_search($inbox,'ALL');

    /* if emails are returned, cycle through each… */
    if($emails) {

    /* begin output var */
    $output = ";

    /* put the newest emails on top */
    rsort($emails);

    /* for every email… */
    foreach($emails as $email_number) {

    /* get information specific to this email */
    $overview = imap_fetch_overview($inbox,$email_number,0);
    $message = imap_fetchbody($inbox,$email_number,2);

    /* output the email header information */
    $output.= 'seen ? ‘read’ : ‘unread’).’”>’;
    $output.= ”.$overview[0]->subject.’ ‘;
    $output.= ‘on ‘.$overview[0]->date.”;
    $output.= ”;

    /* output the email body */
    $output.= ”.$message.”;
    }

    echo $output;
    }

    /* close the connection */
    imap_close($inbox);
    ?>

  76. Dan

    /*

    Gmail to RSS test

    window.addEvent(‘domready’,function() {
    var togglers = $$(‘div.toggler’);
    if(togglers.length) var gmail = new Fx.Accordion(togglers,$$(‘div.body’));
    togglers.addEvent(‘click’,function() { this.addClass(‘read’).removeClass(‘unread’); });
    togglers[0].fireEvent(‘click’); //first one starts out read
    });

    <?php
    $formatcss = "

    ";
    echo $formatcss;

    /* connect to gmail */
    $hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
    $username = 'route5radarproxy@gmail.com';
    $password = 'gothrough';

    /* try to connect */
    $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());

    /* grab emails */
    $emails = imap_search($inbox,'ALL');

    /* if emails are returned, cycle through each… */
    if($emails) {

    /* begin output var */
    $output = ";

    /* put the newest emails on top */
    rsort($emails);

    /* for every email… */
    foreach($emails as $email_number) {

    /* get information specific to this email */
    $overview = imap_fetch_overview($inbox,$email_number,0);
    $message = imap_fetchbody($inbox,$email_number,2);

    /* output the email header information */
    $output.= 'seen ? ‘read’ : ‘unread’).’”>’;
    $output.= ”.$overview[0]->subject.’ ‘;
    $output.= ‘on ‘.$overview[0]->date.”;
    $output.= ”;

    /* output the email body */
    $output.= ”.$message.”;
    }

    echo $output;
    }

    /* close the connection */
    imap_close($inbox);
    ?>

    */

  77. Naresh Kumar

    @Dan: Please help me Dan

    Warning: imap_open() [function.imap-open]: Couldn’t open stream {imap.gmail.com:993/imap/ssl}INBOX in C:\xampp\htdocs\POC\test.php on line 24
    Cannot connect to Gmail: Can’t open mailbox {imap.gmail.com:993/imap/ssl}INBOX: invalid remote specification

    it was a firewall is connecting 993.

    Still i am getting above error

    Regards,
    Naresh

  78. Vinoth S

    Hi all,

    David ur script really nice, But i want mail download from pop3, if u have any idea for that, Please help me…

    Thanks & Regards,
    Vinoth S

  79. Vinoth S

    I’m download the mail from local(means my company) mail server, and the values are spilit and stored into DB, But its a POP amail server, so if u have a idea or something please help me….

  80. Gerrger

    How modify code only view 5 last new mail receive on gmail inbox?

  81. varsha

    Hi, i m receiveing this
    Warning: imap_open() [function.imap-open]: Couldn’t open stream {imap.gmail.com:993/imap/ssl}INBOX in /home/uppstu5/public_html/test_gmail.php on line 8
    Cannot connect to Gmail: Too many login failures
    Plz help me

  82. buzzknow

    how to do this for Yahoo Mail??

    thanks :)

  83. Anon

    This is a nice and useful script but “how the hell do I copy that code??”
    Just line by line? That’s “scary”!! :p

  84. Maurice

    Can someone link a zip with the good files.

  85. princess

    i got the same message.can somebody help

  86. Nik

    Hi

    I have getting the problem that my js file is not working.

    Some error is displaying that “window.addEvent is not a function”.

    I tried but i can’t get any solution so i want to ask that how to resolve this error.

  87. JayJay

    @bob snider
    1248921015.4E4FF544.18054 Date: Wed, 29 Jul 2009 19:30:15 -0700 MIME-Version: 1.0 Content-Type: image/gif Content-Transfer-Encoding: —>base64 Content-Disposition<—- inline

    its encrypted with Base 64 strings, all one needs to do is add a php base64 decode function to render it to text or html. Dav, images should show when decrypted assuming that the correct image html attribute is executed from the browser .

  88. JayJay

    For complete image rendering use urldecode or preg_replace (%22, 3D%22,etc to ” and = etc) after base64 decode scripting, just rendered an image on a html editor with an example gmail source code.
    problem example I had after decoding base64:
    src=”3D%22http://www.example.com/images/email_example-head1.gif%22

  89. Koen Bressers

    Dear David

    Thanks for this code, I found it really useful. However when I send a mail with an attachment it goes all wrong…

  90. Magic Gambit

    Errr….what is that MooTools code?

  91. Magic Gambit

    Btw I use the php code only. On the browser it shows

    Fatal error: Maximum execution time of 60 seconds exceeded in C:\Program Files\xampp\htdocs\display.php on line 36

    what’s wrong?

    • tt

      you have way too many e-mails so your script exceeds maximum time defined in php.ini trying to download them, strict your imap_search($inbox,’ALL’); to lets say imap_search($inbox,’UNSEEN’); and try again ;)

  92. PHP imap

    which PHP imap script should be the best one for me to install?

  93. cady

    http://www.phpkode.com/scripts/tag/imap/ PHP IMAP based client

  94. prima

    i’ve tried the mootools simple accordion code above and it didn’t work. Can you help me how to use it inside php? I put the script inside head tag, is it true? something like this..

    window.addEvent('domready',function()
    {
    var togglers = $$('div.toggler');
    if(togglers.length) var gmail = new Fx.Accordion(togglers,$$('div.body'));
    togglers.addEvent('click',function() { this.addClass('read').removeClass('unread'); });
    togglers[0].fireEvent('click'); //first one starts out read
    });

  95. prima


    window.addEvent('domready',function()
    {
    var togglers = $$('div.toggler');
    if(togglers.length) var gmail = new Fx.Accordion(togglers,$$('div.body'));
    togglers.addEvent('click',function() { this.addClass('read').removeClass('unread'); });
    togglers[0].fireEvent('click'); //first one starts out read
    });

  96. ajay sharavat

    Hi David, I have used you code for fetching gmail inbox in my php application. But i am facing a problem. when I executing the file in browser it taking a very long time to execute. please give me suggestion. Thanks

  97. john

    hi we are getting this error by above code

    Warning: imap_open() [function.imap-open]: Couldn’t open stream {imap.gmail.com:993/imap/ssl}INBOX

    can you tell me solution for this

  98. mark

    getting timeout error. somebody help plz.

  99. Anthony David Adams

    This was working for me at one point, and now I get the following error.

    Warning: imap_open() [function.imap-open]: Couldn’t open stream {imap.gmail.com:993/imap/ssl}INBOX in /hermes/bosweb/web090/b906/ipw.175gcom1/public_html/awaitingreply.php on line 8
    Cannot connect to Gmail: Too many login failures

    i tried changing my gmail password, etc. curious how you would reset gmail or grant permission to this application.

    • Alex Bailey

      Me too. Would love to get this sorted

    • tt

      I did have this problem too but in my case the solution was wrong password, I confused passwords with another account and it seemed correct ;X

  100. karthik

    Hi I am using your gmail code. But I am getting error. See below
    http://knocktechsolutions.com/easy/gmail.php
    How to fix this error.

    Karthik

    • tt

      Couldn’t open stream {pop.gmail.com:995/pop3/ssl}INBOX in /home/knock123/public_html/easy/gmail.php on line 22
      Cannot connect to Gmail: Certificate failure for pop.gmail.com: unable to get local issuer certificate: /C=US/O=Google Inc/CN=Google Internet Authority

      ———————-

      pop.gmail.com:995/pop3/ssl ?

      try using imap {imap.gmail.com:993/imap/ssl}INBOX

  101. Dave Hulse

    Your self-portrait made me think I was hallucinating at 230 am… I didn’t realize it had a mouseover effect but I kept seeing tiny little dots flying around every so often.

  102. Shkur

    how to get X-GM-THRID in gmail via imap php?
    http://code.google.com/intl/ru-RU/apis/gmail/imap/

  103. Nikkee

    Tried this script and it does not work anymore.

    Warning: imap_open() [function.imap-open]: Couldn’t open stream {imap.gmail.com:993/imap/ssl}INBOX in /home/mtharmal/pesiplex/condoclicks/test/gmail.php on line 9
    Cannot connect to Gmail: Certificate failure for imap.gmail.com: unable to get local issuer certificate: /C=US/O=Google Inc/CN=Google Internet Authority
    Notice: Unknown: Certificate failure for imap.gmail.com: unable to get local issuer certificate: /C=US/O=Google Inc/CN=Google Internet Authority (errflg=2) in Unknown on line 0

    Looks like SSL might be an issue here…

    Nikke

  104. Jalpa

    I am hosting the example to my site http://www.mysite.com and its not working saying that “Connection failed to open stream”

    But when i tried to run localhost machine its working fine

    Can anybody give a fine solution to the problem as many are facing the same problem.

  105. atom

    That was what I was looking for. I will right now try it. Thanks for sharing.

  106. Bami

    I am getting the :

    Cannot connect to Gmail: Certificate failure for imap.gmail.com: unable to get local issuer certificate: /C=US/O=Google Inc/CN=Google Internet Authority

    Did someone find the fix?

    thx in advance.

    • Johan Vandeplas

      for all the people having issues with certificate… I found the solution.

      I set novalidate-cert in my servceflags and problem solved!
      [code]
      $config['service_flags'] = '/imap/ssl/novalidate-cert';
      [/code]
      So in this piece of code it’s:
      [code]
      $hostname = '{imap.gmail.com:993/imap/ssl/novalidate-cert'}INBOX';
      [/code]

  107. Atom

    It works great. Now I need to get the attachment out of the email and save it on the server. This seems to be a little bit more difficult.

  108. Ravin

    I’m wondering as to how can I use this code with processmaker so that the case is automatically created the moment processmaker receives mail with specific subject.

    Thanx

  109. Ryan

    You really should moo that PHP trash to node.js. JavaScript is now officially a trendy language. PHP is the worst language ever conceived.

  110. Ryan

    I meant “move” instead of “moo”…

  111. dhietoz

    why i can’t open this message body:

    /* output the email body */
    $output.= ''.$message.'';
    }

    are someone here knows about mootools-1.2.2.js ?
    i has link it like this but no reaction

    please i need little help here..

  112. dhietoz

    why i can’t open this message body:
    /* output the email body */ $output.= '
    '.$message.'
    '; }

    are someone here knows about mootools-1.2.2.js ?
    i has link it like this


    but no reaction please i need little help here..

  113. plr

    Great script, but i couldn’t get it to work, third time trying and I’m getting this error a long load time,

    Warning: imap_open() [function.imap-open]: Couldn’t open stream {imap.gmail.com:993/imap/ssl}INBOX in /home/xxxxxxx/public_html/phpmail/display.php on line 28
    Cannot connect to Gmail: Can’t connect to gmail-imap.l.google.com,993: Connection timed out

  114. MatBoy

    Hi,

    This is very nice to see, but I also can’ t get it work with the mootools.

    Are you willing to upload a working zip here so we can see what goes wrong ?

    That would help a lot !!

    Thanks.

    MatBoy

  115. MatBoy

    Hi,

    This script is great, but I also have the mootools issue which makes that the dropdowns are not working.

    Are you willing to upload a simple working example so we can see what goes wrong as more people have this ?

    Keep up the good work!

    Thanks,

    MatBoy

  116. HELP

    PLEASE I NEED HELP I GET:

    Parse error: syntax error, unexpected $end in /homepages/26/d94605010/htdocs/lz/writecodeonline.com/php/index.php(98) : eval()’d code on line 34

  117. HELP

    Parse error: syntax error, unexpected $end in /homepages/26/d94605010/htdocs/lz/writecodeonline.com/php/index.php(98) : eval()'d code on line 34

    PLEASE I NEED HELP!

  118. mark

    this worked right out of the box!

    david walsh has helped me yet again…. the first time was his rather brilliant interface to tinyurl!

  119. tanay

    @deepak

    try <?php instd of <?

  120. tanay

    @deepak try <?php instead of <?

  121. Karthik Malla

    How to add email forwarding to other email address using your code.

  122. Caleb

    All I get when I run the script is:
    Warning: imap_open() [function.imap-open]: Couldn’t open stream {imap.gmail.com:993/imap/ssl}INBOX in /Applications/XAMPP/xamppfiles/htdocs/mail.php on line 24
    Cannot connect to Gmail: Can’t open mailbox {imap.gmail.com:993/imap/ssl}INBOX: invalid remote specification

    I’m using localhost. Would that be the problem?

    Can someone help me?

    Thanks.

  123. Suraj

    hi,
    great code, but i get
    Maximum execution time of 30 seconds exceeded
    Can we increase a time. I have 3700 mail in my inbox,

  124. Sid

    Hi David,

    Is there any way to fetch mail from sent box as well as inbox.

    I have use your sample code to retrieve the mail from Gmail and it works awesome.But now i want to implement the system where i can search for particular mail id and it will be presented to me.and this email id might come from the inbox as well as the Sent mail.

    I implemented the search also but all the time i need to see the mails in inbox as well as sent items,

    • Muhammad Tanweer

      Hi Sid,

      To get the emails from sent items in gmail, use the host name like this.
      {imap.gmail.com:993/imap/ssl}[Gmail]/Sent Mail

      This should work.

      Thank,
      Muhammad

  125. Magheskumar

    I tried this code wamp server local system is working perfectly but hosting this script it show error like
    Can’t connect to gmail-pop.l.google.com,995: Connection refused
    Did someone find the fix?

    Thank u

  126. Varun Jain

    Hello David,
    I Used Your Script and with detail reading about php Imap m able to use it accordingly
    but m still unable to fetch the spam mail
    any idea how to do it ?

  127. akshay

    Whenever i try to connect with gmail server it give me fatel error !
    i had try everthing to get my mails from gmail !
    please help me to solve this mistake
    this is my code ………

    div.toggler { border:1px solid #ccc; background:url(gmail2.jpg) 10px 12px #eee no-repeat; cursor:pointer; padding:10px 32px; }
    div.toggler .subject { font-weight:bold; }
    div.read { color:#666; }
    div.toggler .from, div.toggler .date { font-style:italic; font-size:11px; }
    div.body { padding:10px 20px; }

    window.addEvent(‘domready’,function() {
    var togglers = $$(‘div.toggler’);
    if(togglers.length) var gmail = new Fx.Accordion(togglers,$$(‘div.body’));
    togglers.addEvent(‘click’,function() { this.addClass(‘read’).removeClass(‘unread’); });
    togglers[0].fireEvent(‘click’); //first one starts out read
    });

    <?php

    /* connect to gmail */
    $hostname = '{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX';
    $username = 'akshayjindal1990@gmail.com';
    $password = 'getopen07it004';

    /* try to connect */
    $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());

    /* grab emails */
    $emails = imap_search($inbox,'ALL');

    /* if emails are returned, cycle through each… */
    if($emails) {

    /* begin output var */
    $output = '';

    /* put the newest emails on top */
    rsort($emails);

    /* for every email… */
    foreach($emails as $email_number) {

    /* get information specific to this email */
    $overview = imap_fetch_overview($inbox,$email_number,0);
    $message = imap_fetchbody($inbox,$email_number,2);

    /* output the email header information */
    $output.= 'seen ? ‘read’ : ‘unread’).’”>’;
    $output.= ”.$overview[0]->subject.’ ‘;
    $output.= ”.$overview[0]->from.”;
    $output.= ‘on ‘.$overview[0]->date.”;
    $output.= ”;

    /* output the email body */
    $output.= ”.$message.”;
    }

    echo $output;
    }

    /* close the connection */
    imap_close($inbox);

    ?>

    Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\mymail\mail.php on line 49

  128. Jorge Caraballo

    Thank you very much Dave!!! I really appreciate your effort in sharing your knowledge!!!

  129. Geoff

    Hi tried running your script and I get this error. Kindly help I have tried everything and nothing seems to work.

    Warning: imap_open() [function.imap-open]: Couldn’t open stream {imap.gmail.com:993/ssl/novalidate-cert} in/home/spifiel1/public_html/email.php on line 8
    Cannot connect to Gmail: Can’t connect to gmail-imap.l.google.com,993: Connection timed out

  130. farooq

    hi,

    I wuld like to connnect to the hosting email of my website. I am able to connect to gmail but i want to connect to my website email. I have cpanel and port used is 110. getting error on imap open function. imap host i am using

  131. sarmen

    for anyone getting errors for imap. if you are on a mac and using mamp. mamp does not have imap in it yet. cehck this page http://forum.mamp.info/viewtopic.php?f=4&t=9422

  132. anu

    Hi David Walsh
    I am getting this error..

    Warning: imap_open() [function.imap-open]: Couldn’t open stream {imap.gmail.com:993/imap/ssl}INBOX in /home/coimbato/public_html/cp/mailling.php on line 31
    Cannot connect to Gmail: Can’t connect to gmail-imap.l.google.com,993: Connection refused

    i uploaded it and tested..but receiving the same…

    • martin

      Can’t sure if it related to SELinux, but i had selinux enabled and got following message:

      Warning: imap_open() [function.imap-open]: Couldn’t open stream {imap.gmail.com:993/imap/ssl}INBOX in /var/www/html/imap.php on line 34
      Cannot connect to Gmail: Can’t connect to gmail-imap.l.google.com,993: Permission denied

      after disable related selinux permission by
      setsebool -P httpd_can_network_connect=1
      script work well
      (googled said that /var/log/message or /var/log/httpd/error_log should had selinux warning, but i can’t find it at CentOS6 x64)

  133. gaurav

    Fatal error: Call to undefined function imap_open() in C:\wamp\www\prog\proj.php on line 33

    i am using wamp server,any suggestion how to remove it??pls answer asap..

  134. Sammy Geerts


    title . '';
    echo 'You have ' . $xml->fullcount . ' ' . $xml->tagline . '';
    foreach ($xml->entry as $child) {
    echo '' . $child->title . '';
    echo '' . $child->author->name . '<' . $child->author->email . '>';
    echo '' . $child->modified . '';
    echo '' . $child->summary . ' link['href'] . '" target="_blank">Read more.. .';
    }
    ?>

  135. Earthenware

    Very useful mail-handling script, thank you.

  136. samuel caldas

    I would like to make a system similar to that outlook. could you help me? your script is not working well.

  137. Jean Fréor

    Hi,

    For those who hav got a “invalid remote …” error whith MAMP (Mac computer) trying to connect to a SSL IMAP server as Gmail, I have found the solution here, and… it really works for me :

    http://www.vargatron.com/2009/03/imap-ssl-with-mamp/comment-page-1/#comment-152

  138. Shareef

    hey give me ful code :( i dont get it correctly…how i include mootools???

  139. Jorge Caraballo

    Hi Shareef

    You can see the example code of david walsh that i used.

    example code of david walsh by jorge caraballo

    It works perfect in my own domain and i share it. You can try it using your own mail server settings.

    Good luck.

    Best Regards.

  140. Prakash

    David,

    While i am using this code some of the mails are skipped.Rest of the mails are downloaded as well.Any suggestion…

  141. Gaurav

    Hello everyone,
    I am getting this error. From the above posts i tried to rectify, by changing INBOX to SENT MAIL and so on..but still giving me the same error. Does anyone else has face the same problem. if so please do share with me how to rectify it.

    Warning: imap_open() [function.imap-open]: Couldn’t open stream {imap.gmail.com:993/imap/ssl}INBOX in C:\xampp\htdocs\email\index1.php on line 32
    Cannot connect to yourdomain.com: Too many login failures

  142. Gaurav

    Fatal error: Maximum execution time of 60 seconds exceeded in C:\xampp\htdocs\email\index1.php on line 51

    getting this error whenever i try to run it..

  143. Mark

    Hi,

    Is there any way to figure out the size of the gmail account using API, prior to downloading the emails?

    Thanks,

    -Mark

  144. Jan

    Wow, i’ve been looking for such simple code for long time. And your live demo made me believe again, that accessing GMail via PHP can actually work. :-)

    I am wondering if there are any special requirements (php-imap client version or so) since I never get connected with imap_open on my environment. all ports opened. latest php release.

    wbr
    Jan

  145. Bert-Jan

    Thanks, this was most helpful !

  146. mayur saxena

    I am trying to run this script on my server but it shows nothing can you send me the original script please

  147. Dhaval

    Hi David,

    I am getting numbers of mails but it didn’t display mails and throwing below error

    “Warning: imap_fetchbody() [function.imap-fetchbody]: Bad message number line 24″

    I can’t get why its throwing this error?

  148. Dhaval

    Hi David,

    I am getting number of mails but didn’t get any subject or other stuff even it throws below Warning

    Warning: imap_fetchbody() [function.imap-fetchbody]: Bad message number on line 24

    and below is my code

    $hostname = “{imap.gmail.com:993/imap/ssl}INBOX”;
    $username = “username”;
    $password = “password”;

    $inbox = imap_open($hostname,$username,$password);
    $emails = imap_search($inbox,’ALL’);

    if($emails)
    {
    $output = ”;

    rsort($emails);

    foreach($emails as $email_numbers)
    {
    echo $email_numbers;

    $overview = imap_fetch_overview($inbox,$email_number,0);
    $message = imap_fetchbody($inbox,$email_number,2);

    $output .= ”;
    $output .= ”.$overview[0]->subject.”;
    $output .= ”.$overview[0]->from.”;
    /* $output .= ”.$overview[0]->date.”;*/
    $output .= ”;

    }

    echo $output;
    }

    imap_close($inbox);

  149. sarwar

    hi David,

    i have used ur code. But it prints these following php lines instead of output:

    seen ? ‘read’ : ‘unread’).’”>’;
    $output.= ”.$overview[0]->subject.’ ‘;
    $output.= ”.$overview[0]->from.”;
    $output.= ‘on ‘.$overview[0]->date.”;
    $output.= ”;

    /* output the email body */
    $output.= ”.$message.”;

    }

    echo $output;
    }

    /* close the connection */
    imap_close($inbox);

    #######my full code####

    david walsh code

    window.addEvent(‘domready’,function() {
    var togglers = $$(‘div.toggler’);
    if(togglers.length) var gmail = new Fx.Accordion(togglers,$$(‘div.body’));
    togglers.addEvent(‘click’,function() { this.addClass(‘read’).removeClass(‘unread’); });
    //togglers[0].fireEvent(‘click’); //first one starts out read
    });

    <?php
    /* connect to yourserver */
    $hostname = '{gmail.com:993/imap/ssl}INBOX'; /* Set this according to your own mail server*/
    $username = 'myemail';
    $password = 'mypass';

    /* try to connect */
    $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to yourdomain.com: ' . imap_last_error());

    /* grab emails */
    $emails = imap_search($inbox,'ALL');

    /* if emails are returned, cycle through each… */
    if($emails) {

    /* begin output var */
    $output = '';

    /* put the newest emails on top */
    rsort($emails);

    /* for every email… */
    foreach($emails as $email_number) {

    /* get information specific to this email */
    $overview = imap_fetch_overview($inbox,$email_number,0);
    $message = imap_fetchbody($inbox,$email_number,1);

    /* output the email header information */
    $output.= 'seen ? ‘read’ : ‘unread’).’”>’;
    $output.= ”.$overview[0]->subject.’ ‘;
    $output.= ”.$overview[0]->from.”;
    $output.= ‘on ‘.$overview[0]->date.”;
    $output.= ”;

    /* output the email body */
    $output.= ”.$message.”;

    }

    echo $output;
    }

    /* close the connection */
    imap_close($inbox);
    ?>

    ##
    I hope I will get quick response. Thanks in advance.

  150. Sagar Ravkhande

    can any one give me code for the following program using IMAP—–>
    A GUI in which username and password along with the message content to be searched is asked and you have to dispaly message content of user who is logging currently to gmail and whose search message content is matched wt messages in inbox as well as in spam folder if any plz help..???

  151. asd


    /* output the email body */
    $output.= ”.$message.”;

    }

    echo $output;
    }

    /* close the connection */
    imap_close($inbox);

    #######my full code####

    david walsh code

    window.addEvent(‘domready’,function() {
    var togglers = $$(‘div.toggler’);
    if(togglers.length) var gmail = new Fx.Accordion(togglers,$$(‘div.body’));
    togglers.addEvent(‘click’,function() { this.addClass(‘read’).removeClass(‘unread’); });
    //togglers[0].fireEvent(‘click’); //first one starts out read
    });

    ’;
    $output.= ”.$overview[0]->subject.’ ‘;
    $output.= ”.$overview[0]->from.”;
    $output.= ‘on ‘.$overview[0]->date.”;
    $output.= ”;

    /* output the email body */
    $output.= ”.$message.”;

    }

    echo $output;
    }

    /* close the connection */
    imap_close($inbox);


Be Heard!

Share your thoughts without being a jerk! And wrap your code in <code> tags, f00!

Name*:
Email*:
Website: