I'm posting my code for reading email
It have problem with displaying images inside email as well as it can not display email properly other than English language
Is there need of email parsing?
I don't know how to go with email parsing
config.php
<?php
$ServerName = "{mail.host.com:995/pop3/ssl/novalidate-cert}INBOX";
$UserName = "user_name@host.com";
$PassWord = "password";
$mbox = imap_open($ServerName, $UserName,$PassWord)
or die("Could not open Mailbox - try again later!");
?>
index.php
<?php
include('config.php');
if ($hdr = imap_check($mbox)) {
echo "Num Messages " . $hdr->Nmsgs ."\n\n<br><br>";
$msgCount = $hdr->Nmsgs;
} else {
echo "failed";
}
$MN=$msgCount;
$overview=imap_fetch_overview($mbox,"1:$MN",0);
$size=sizeof($overview);
echo "<table border=\"1\" align=\"center\" cellspacing=\"0\" width=\"70%\">";
for($i=$size-1;$i>=0;$i--){
$val=$overview[$i];
$msg=$val->msgno;
$from=$val->from;
$date=$val->date;
$subj=strip_tags($val->subject);
$seen=$val->seen;
$from = ereg_replace("\"","",$from);
// MAKE DATE DISPLAY
list($dayName,$day,$month,$year,$time) = split(" ",$date);
$time = substr($time,0,5);
$date = $day ." ". $month ." ". $year . " ". $time;
if ($bgColor == "#F0F0F0") {
$bgColor = "#FFFFFF";
} else {
$bgColor = "#F0F0F0";
}
if (strlen($subj) > 60) {
$subj = substr($subj,0,59) ."...";
}
echo "<tr bgcolor=\"$bgColor\">
<td colspan=\"2\" width=\"25%\">$from</td>
<td colspan=\"2\" width=\"60%\"><a href=\"readmsg.php?id=$msg\">$subj</a></td>
<td class=\"tblContent\" colspan=\"2\" width=\"5%\">$date</td>
</tr>\n";
}
echo "</table>";
imap_close($mbox);
?>
readmsg.php
<?php
include('config.php');
$b= $_REQUEST['id'];
$msgno=$b;
$msg_number=$b;
function get_mime_type(&$structure) {
$primary_mime_type = array("TEXT", "MULTIPART","MESSAGE", "APPLICATION", "AUDIO","IMAGE", "VIDEO", "OTHER");
if($structure->subtype) {
return $primary_mime_type[(int) $structure->type] . '/' .$structure->subtype;
}
return "TEXT/PLAIN";
}
function get_part($stream, $msg_number, $mime_type, $structure = false,$part_number = false) {
if(!$structure) {
$structure = imap_fetchstructure($stream, $msg_number);
}
if($structure) {
if($mime_type == get_mime_type($structure)) {
if(!$part_number) {
$part_number = "1";
}
$text = imap_fetchbody($stream, $msg_number, $part_number);
if($structure->encoding == 3) {
return imap_base64($text);
} else if($structure->encoding == 4) {
return imap_qprint($text);
} else {
return $text;
}
}
if($structure->type == 1) /* multipart */ {
while(list($index, $sub_structure) = each($structure->parts)) {
if($part_number) {
$prefix = $part_number . '.';
}
$data = get_part($stream, $msg_number, $mime_type, $sub_structure,$prefix . ($index + 1));
if($data) {
return $data;
}
} // END OF WHILE
} // END OF MULTIPART
} // END OF STRUTURE
return false;
} // END OF FUNCTION
// GET TEXT BODY
$dataTxt = get_part($mbox, $msgno, "TEXT/PLAIN");
// GET HTML BODY
$dataHtml = get_part($mbox, $msgno, "TEXT/HTML");
if ($dataHtml != "") {
$msgBody = $dataHtml;
$mailformat = "html";
} else {
$msgBody = ereg_replace("\n","<br>",$dataTxt);
$mailformat = "text";
}
// To out put the message body to the user simply print $msgBody like this.
if ($mailformat == "text") {
echo "
<html>
<head>
<title>Messagebody</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
</head>
<body bgcolor=\"white\">
<table border=\"1\" align=\"center\" width=\"80%\" bgcolor=\"#999999\"><tr><td>
$msgBody
</td></tr></table>
</body>
</html>";
} else {
echo "
<html>
<head>
<title>Messagebody</title>
</head>
<body bgcolor=\"white\">
<table border=\"1\" align=\"center\" width=\"80%\" bgcolor=\"#999999\"><tr><td>";
echo $msgBody; // It contains all HTML HEADER tags so we don't have to make them.
echo "</td></tr></table>
</body>
</html>";
}
?>