I have this code which shows the body of my email but it's not in format.
IE: it does not have paragraphing bold text if set ect.
It shows like this
Dear Mr Smith, Thank you for your feedback. Your reference number is 055-000066. A consultant will be in contact.....
not
Dear Mr Smith,
Thank you for your feedback. Your reference number is 055-000066. A consultant will be in contact.....
how can i fix this?
<?php
$mbox = $link;
$mid = $id;
$struct = imap_fetchstructure($mbox, $mid);
$parts = $struct->parts;
$i = 0;
if (!$parts) { /* Simple message, only 1 piece */
$attachment = array(); /* No attachments */
$content = imap_body($mbox, $mid);
} else { /* Complicated message, multiple parts */
$endwhile = false;
$stack = array(); /* Stack while parsing message */
$content = ""; /* Content of message */
$attachment = array(); /* Attachments */
while (!$endwhile) {
if (!$parts[$i]) {
if (count($stack) > 0) {
$parts = $stack[count($stack)-1]["p"];
$i = $stack[count($stack)-1]["i"] + 1;
array_pop($stack);
} else {
$endwhile = true;
}
}
if (!$endwhile) {
/* Create message part first (example '1.2.3') */
$partstring = "";
foreach ($stack as $s) {
$partstring .= ($s["i"]+1) . ".";
}
$partstring .= ($i+1);
if (strtoupper($parts[$i]->disposition) == "ATTACHMENT") { /* Attachment */
$attachment[] = array("filename" => $parts[$i]->parameters[0]->value,
"filedata" => imap_fetchbody($mbox, $mid, $partstring));
} elseif (strtoupper($parts[$i]->subtype) == "PLAIN") { /* Message */
$content .= imap_fetchbody($mbox, $mid, $partstring);
}
}
if ($parts[$i]->parts) {
$stack[] = array("p" => $parts, "i" => $i);
$parts = $parts[$i]->parts;
$i = 0;
} else {
$i++;
}
} /* while */
} /* complicated message */
echo "Analyzed message $mid, result: <br />";
echo "Content: $content<br /><br />";
echo "Attachments:"; print_r ($attachment);
?>