FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Getting unread email count using PHP

 


ChrisCh
Hey there. When members login to my site, they are told if they have any new private messages, and if so, are told how many. While this is quite simple to do (as the system is run via a database), I wasn't quite sure how to go about doing the same thing for new emails. I'm hoping it'll end up something like this:

If user has webmail on my site (email address and email password will be stored in the user's row in the main database), then check and see how many new (unread) emails they have, and return the number.

I will only need to check the number for those that have email accounts on my website - so there is no need to check outside websites or other email services.

So yea, if anyone knows how to use PHP to connect with FriHost's email servers, I'd love to hear from you! Smile
kv
Here is a function I modified to suit your needs

Code:
function CountUnreadMails($host, $login, $passwd)
{

    $mbox = imap_open("{{$host}/pop3:110}", $login, $passwd);

    $count = 0;
    if (!$mbox)
    {
        echo "Error";
    }
    else
    {
        $headers = imap_headers($mbox);
        foreach ($headers as $mail)
        {
            $flags = substr($mail, 0, 4);
            $isunr = (strpos($flags, "U") !== false);
       if ($isunr)
      $count++;
        }
    }

    imap_close($mbox);
    return $count;
}
ChrisCh
Thanks very much for that! I'll try putting it into my welcome page soon. Smile
Diablosblizz
Where do you put the login information? How does it know to connect to that mail account?

Just wondering, I would like to use this script.
kv
use it like this

Code:
$cnt=CountUnreadMails("localhost", "testuser", "passwd");
echo "user  testuser has $cnt unread mails";
loginos
When I am trying to use this function on frihost I am receiving an error message
"Fatal error: Call to undefined function: imap_open()"

Can somebody help me?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.