March 0902

cfmail and white space problem

Ok I don’t often have to deal with ColdFusion, but at work there are still a few legacy websites using it and every so often I have to make some updates / changes (at least until we’ve finished migrating things over to .Net, and Sitefinity). However this morning I needed to make a change one of the forms so as well as saving details to the database, it also emails the results to someone.

One of the nice things about Coldfusion is that it is pretty easy to use, there are quite a few handy tags to use and cfmail is one of those, set a few properties on the attributes (such as who the mail is from, who its going to and the subject) the content for the mail message is simply everything between the start and close tags. To put text on the next line you simply add a line break (not \n or <br /> or VbCrlf), so it’s treated a bit like a <pre> tag, but it seems that only works IFF the end of the line is not an output (wrapped in # markers). When the last thing on the end of the line is wrapped in output markers cfmail ignores the fact that you’ve added a line break, you can add another line break but then cfmail adds both line breaks. You could make the whole email an html mail, but then you’d have to control all line breaks with a <br /> tag and that’s more hassle than its worth (for a simple email anyway).

The solution I landed on was simply to add a character to the end of the line, in my case a full stop (period) ‘.’ character was a good candidate. Somewhat obscure, though I can understand why it behaves like that, a bit like C# something has to indicate that the code block is over and ‘normal’ html should resume.

Permalink | Comments (0)
Comments are closed