Skip to main content
Participating Frequently
August 14, 2008
Question

how to add html code to format within CFMAIL

  • August 14, 2008
  • 12 replies
  • 2857 views
Hello,
I am a newbie to CFMAIL and like to ask if there is a way to format the output within CFMAIL. I tried to enter HTML code within CFMAIL and I got the html code from output.

I created a simple comments form for users to submit their comments, and send this result to my email.

Here is my code:

<CFMAIL TO = "test@test.com"
FROM = "test@test.com"
SUBJECT = "test"
>

New suggestions: <br />
<b>Name:</b> #name#
<b>Comments:</b> #comments#
</CFMAIL>

On the output, I received all html code and when a user enter multiple rows of suggestions, they are not aligned properly in the email.

How do I format the output within cfmail?
How do I get good format for the comments with multiple rows?

Thanks very much.

Jenny.
    This topic has been closed for replies.

    12 replies

    August 15, 2008
    Azadi, I tried that one along with chr(13), \n, \r, and \r\n.. still, nothing.
    Inspiring
    August 15, 2008
    try:
    #replace(comments, chr(10), "<br>", "ALL")#

    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/
    Participating Frequently
    August 15, 2008
    It may be more complicated.
    thanks.
    August 14, 2008
    I did a search for this exact problem, and came upon this site:
    http://jennifermadden.com/javascript/stringEscape.html

    However this will only help solve your problem on the client side, and it may throw your users off a bit by inserting html into the text box. My original replace statement will insert spaces only if the user enters in two spaces, and will not work for one.

    Possibly the best way to get everything to work as needed, would be to setup a wysiwyg editor.
    Inspiring
    August 14, 2008
    search on <cfmailparam>
    Participating Frequently
    August 14, 2008
    I search on google to see if I can make the 'comments' box to be plain text, but never find this information.
    Thanks.
    Inspiring
    August 14, 2008
    I'm not sure, but you might be able to set it up so that part of your mail body is html and part is plain text. The from textareas is what you want in plain text.

    I've never tried it but I vaguely remember reading something like that on these forums.
    Participating Frequently
    August 14, 2008
    It worked.

    Can you please help me with the 'multiple rows' when user enter in separate lines? I like to have result in the same way as the user type in the comment box.

    Thanks.
    Participating Frequently
    August 14, 2008
    One more question, I created a selection drop list for multiple selection which allow users to select more than one option.

    <CFSELECT NAME="choice" SIZE="3" multiple="true">
    <OPTION>good
    <OPTION>bad
    <OPTION>Other
    </CFSELECT>
    When a user select both bad and other, then the output is "bad,other"

    How do I remove ',' or 'comma' and replace it with a ' ' or 'space'?

    thanks.
    August 14, 2008
    quote:

    Originally posted by: jennypretty2
    One more question, I created a selection drop list for multiple selection which allow users to select more than one option.

    <CFSELECT NAME="choice" SIZE="3" multiple="true">
    <OPTION>good
    <OPTION>bad
    <OPTION>Other
    </CFSELECT>
    When a user select both bad and other, then the output is "bad,other"

    How do I remove ',' or 'comma' and replace it with a ' ' or 'space'?

    thanks.


    #replace(choice, ',', ' ', 'ALL')#
    Participating Frequently
    August 14, 2008
    I tried exactly what you said but it did not return the separate rows.
    Please advice.
    thanks.