Question

I have wrote a simple php script which reads an IMAP email account and displays the body of the most recent mail. There is just one problem, it won't keep the new lines properly. It just puts it all on one line.

I use

imap_fetchbody($conn, $latest, "1");

to read the body of the email. How do I keep the original formatting with all the proper line breaks. Much thanks

Was it helpful?

Solution

Are you outputting to a browser? Try using nl2br. The doc says:

Inserts HTML line breaks before all newlines in a string

Example:

<?php
echo nl2br("foo isn't\n bar");
//output: foo isn't<br /> bar
?>

OTHER TIPS

Why don't you try the print_r option which is in built in PHP?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top