Hiya, I have been following an email client tutorial but am having trouble with viewing emails. I can get it to display the from, to, date and subject but the message and any attachments do not display. I have tried a few different things but can't get it to work. Please can someone have a look at the code for the view page and give me a clue where it is wrong. It must be a problem with the code because when I load the email account using squirrel mail I can see the message.
ThanxPHP Code:<?php
session_start(); //Use the registered session.
//log into the server and get the total number of messages
$username = $_SESSION['username'];
$epw = $_SESSION['password'];
$inbox = imap_open("{".$emailserver."}", $username.$domain, $epw);
$total = imap_num_msg($inbox);
// get the message structure
$id = $_GET['id'];
$headers = imap_header($inbox, $id);
$structure = imap_fetchstructure($inbox, $id);
$parsedStructure = array();
$parts = $structure->parts;
//before we start building our multipart message handling, set some common values
// message types
$type = array("text", "multipart", "message", "application", "audio", "image", "video", "other");
// message encodings
$encoding = array("7bit", "8bit", "binary", "base64", "quoted-printable", "other");
if (sizeof($parts>1))
{
for($i=0; $i<sizeof($parts); $i++)
{
$parsedStructure[$i]["pid"] = ($i+1);
$currentpart = $parts[$i];
if ($currentpart->type == "") { $currentpart->type = 0; }
$parsedStructure[$i]["type"] = $type[$currentpart->type] . "/" . strtolower($currentpart->subtype);
if ($currentpart->encoding == "") { $currentpart->encoding = 0; }
$parsedStructure[$i]["encoding"] = $encoding[$currentpart->encoding];
$parsedStructure[$i]["size"] = strtolower($currentpart->bytes);
$parsedStructure[$i]["disposition"] = strtolower($currentpart->disposition);
if (strtolower($currentpart->disposition) == "attachment")
{
$params = $currentpart->parameters;
foreach ($params as $p)
{
if($p->attribute == "NAME")
{
$parsedStructure[$i]["filename"] = $p->value;
break;
}
}
}
}
// now keep only the attachment information separate
for($i=0; $i<sizeof($parsedStructure); $i++)
{
if($parsedStructure[$i]["disposition"] == "attachment")
{
$attachments[] = $parsedStructure[$i];
}
}
}
// we can now handle our Text and HTML body appropriately and prepare a listing of our attachments
?>
<div id="main"><br />
<div class="ttlhead"><h2>Read Email</h2></div>
<br />
<a href="compose.php?reply=<?php echo($id); ?>">Reply</a>
<a href="delete.php?del=<?php echo($id); ?>">Delete</a>
<a href="inbox.php">Back to Inbox </a>
<?php
echo '<br />
<div class="clearfix">
<div class="row100t">From: </div>
<div class="row680">
<div class="pmcont">'.htmlspecialchars($headers->fromaddress).'</div>
</div></div>
<div class="clearfix">
<div class="row100t">Date: </div>
<div class="row680">
<div class="pmcont">'.$headers->Date.'</div>
</div></div>
<div class="clearfix">
<div class="row100t">Subject: </div>
<div class="row680">
<div class="pmcont">';
if ($headers->Subject) {
echo $headers->Subject;
} else {
echo "No subject";
} echo '</div>
</div></div>
<div class="clearfix">
<div class="row100t">Message: </div>
<div class="row680">
<div class="pmcont">';
if(is_array($parsedStructure)) {
for($i=0; $i<sizeof($parsedStructure); $i++) {
if(($parsedStructure[$i]["type"] == "text/plain" || $parsedStructure[$i]["type"] == "message/rfc822") && $parsedStructure[$i]["disposition"] != "attachment"){
echo "<p />";
echo htmlspecialchars(stripslashes(trim(imap_fetchbody($inbox, $id, $parsedStructure[$i]["pid"]))));
echo "<p />";
}
if($parsedStructure[$i]["type"] == "text/html") {
echo "<p />";
echo (imap_fetchbody($inbox, $id, $parsedStructure[$i]["pid"]));
}
echo "</p>";
}
} else {
echo htmlspecialchars(stripslashes(trim(imap_body($inbox, $id))));
} echo '</div>
</div></div><br />
<div class="clearfix">
<div class="row100t">Attachments: </div>
<div class="row680">
<div class="pmcont">';
for ($i=0; $i<sizeof($attachments); $i++) {
echo ('<li><a href=download.php?id='.$id.'&pid='.$attachments[$i]["pid"] . '&type=' . $attachments[$i]["type"] . '&filename=' . $attachments[$i]["filename"] . '&encoding=' . $attachments[$i]["encoding"] . '>' . $attachments[$i]["filename"] . ' (' . ceil($attachments[$i]["size"]/1024) . ' KB)</a>');
echo ('<br>');
} echo '</div>
</div></div>';
?>![]()




Bookmarks