Hello!
I hope you can help me with the below script please.
This works brilliantly at checking mailboxes (we have this code over and over for different mailboxes). However, we wanted to add more to it, if possible.
I asked on here before, and because of the protocol I couldn't have a message saying the total messages, and how many were NEW. I wondered why that was, because Webmails for example can distinguish between new / old.
However, what I wanted to do, if possible was add the following...
At the moment, it just says for example: 3 messages in Inbox.
Would it be possible that if there was 1 or more, that more gets added to that? For it to say the following, for the LATEST email it received:
[b]3[/b] messages in Inbox (LAST: [b]Subject:[/b] Subject-of-mail [b]From:[/b] From@Email [b]On:[/b] Received-date)
Also, if it possible for it to distinguish between new/old, instead of just X messages in Inbox, could it say: 5 messages in Inbox (X new)?
Any help doing this would be MUCH appreciated!
The code:
<?php
// mail server settings
$host="192.168.2.15";
$port = 110;
$user = "mail@domain.com";
$pass = "password";
// open a client connection
$fp = fsockopen ($host, $port, $errno, $errstr);
// if a handle is not returned
if (!$fp)
{
exit("Error: could not open socket connection\n");
}
else
{
// get the welcome message
$welcome = fgets ($fp, 150);
// check for success code
if (substr($welcome, 0, 3) == "+OK")
{
// send username and read response
fputs ($fp, "USER $user\n");
fgets($fp, 50);
// send password and read response
fputs ($fp, "PASS $pass\n");
$ack = fgets($fp, 50);
// check for success code
if (substr($ack, 0, 3) == "+OK")
{
// send status request and read response
fputs ($fp, "STAT\n");
$status = fgets($fp, 50);
if (substr($status, 0, 3) == "+OK")
{
// shut down connection
fputs ($fp, "QUIT\n");
fclose ($fp);
}
// error getting status
else
{
echo ("Server said: $status");
}
}
// auth failure
else
{
echo ("Server said: $ack");
}
}
// bad welcome message
else
{
exit ("Bad connection string\n");
}
// get status string
// split by spaces
$arr = explode(" ", $status);
// the second element contains the total number of messages
echo $arr[1] . " message(s) in Inbox.";
}
?>