BTW: This happens because HTML does not interpret line breaks. The nl2br (new line to break) function inserts XHTML line breaks (<br/>) where ever newline characters (\n) occur in the string.
Besides server-side technologies like PHP, there are a few client-side options as well.
Then add a stylesheet rule for browsers that don't support the <pre> element, though I can't remember ATM which browsers don't support it.
The preceding CSS rule preserves both the whitespace and the line breaks.
A PHP/C-Client/PEAR solution for webmail