How to display email message count using PHP

Post Reply
Tony
Lieutenant
Lieutenant
Posts: 86
Joined: Tue Jul 21, 2009 4:11 pm

How to display email message count using PHP

Post by Tony » Sun Nov 29, 2009 3:54 am

This simple script creates an image that can be used on any page to display the number of email messages in your inbox. You could even put this on your desktop if you use an html page for your background image. In your html, put an <img> tag for the image, such as the one below. Do not put width or height parameters in the img tag as this will distort the generated image.

Code: Select all

<img src="http://yourdomain.com/messages.php" style="border: inset 3px;"> 
Name the script below messages.php.

Code: Select all

<?php 
$server = "mail.yourdomain.com"; 
$user = "XXXXXX"; 
$password = "YYYYYY"; 
$host = "{".$server.":143"."}"."INBOX"; 
$msgstream = imap_open($host, $user, $password); 
$check = imap_mailboxmsginfo($msgstream); 
$count = $check->Nmsgs; 
imap_close($msgstream); 
// generate display image 
$width = (strlen($count)*8)+8; 
$im = @imagecreate($width, 18); 
$background_color = imagecolorallocate($im,255,255,255); 
$text_color = imagecolorallocate($im,0,0,0); 
imagestring($im,4,4,2,$count,$text_color); 
imagepng($im); 
imagedestroy($im); 
?>
Post Reply

Return to “PHP & MySQL”