// To connect to a POP3 server on port 110 on the local server, use:
$mbox = imap_open ("{localhost:110/pop3}INBOX", "user_id", "password");
imap_open("{pop.gmail.com:995/pop3/ssl/novalidate-cert}INBOX", $username, $pasword);$mbox = imap_open("{pop.gmail.com:993/pop3/ssl/novalidate-cert}INBOX", $username, $pasword);I use Google Apps for my email and got it working, so it shouldn’t be a problem to use GMail.
I tried connecting to the POP server instead, but still ran into trouble (RE: gmail). According to some comments to the imap_open function, the following should work for POP:
imap_open("{pop.gmail.com:995/pop3/ssl/novalidate-cert}INBOX", $username, $pasword);
However, I am still having trouble with imap or pop, and I have confirmed that both are enabled in my gmail settings. I google search reveals others are running into similar problems. It might just be my environment. Regardless, I can’t wait to see how this progresses.
imap_num_msg(): supplied argument is not a valid imap resource
<?php $uname = '[email protected]'; // mailbox login $upass = 'passwd'; // mailbox password $mailserver = 'imap.gmail.com'; // mail server name, or use localhost $parent = 3; // the ID of the parent document for these documents // connect to the mail server $mbox = imap_open("{imap.gmail.com:993/imap/ssl/readonly}INBOX", $uname, $upass, OP_READONLY); //$total = imap_num_msg($inbox); //echo $total; // if you get a number here, you're in business!! // ^^didn't work - imap_num_msg(): supplied argument is not a valid imap resource $listing = imap_search($mbox, "TO yankeedeuce"); foreach($listing as $msg) { $message = imap_body($mbox, $msg); $header = imap_header($mbox, $msg); $from = $header->from; foreach ($from as $id => $object) { $fromname = $object->personal; //from name $fromaddress = $object->mailbox . "@" . $object->host; // from email address } $articletitle = $header->subject; // subject line $articledate = $header->date; // date sent echo "<h3>$articletitle</h3> From: $fromname ($fromaddress) <br/> $articledate <p>$message</p><br />"; } ?>