Skip to main content
Participating Frequently
August 14, 2008
Question

how to add html code to format within CFMAIL

  • August 14, 2008
  • 12 replies
  • 2864 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

    Participating Frequently
    August 14, 2008
    It worked almost perfectly.
    If a user enter in comments box in multiple lines like this:
    1. abc
    2. testss
    3. dsf22

    When I viewed the result within email, it does not break down to rows but shows just one line.

    Please help.

    Thanks.
    August 14, 2008
    Try replacing #comments# with:

    #replace(paragraphFormat(comments),"<P>","<br /><br />")#
    Inspiring
    August 14, 2008
    You need to define TYPE="html" (within the CFMAIL tag), this means your email is sent as html rather than plain text.

    Then I would use tables to format the email,setting the width of the email no more than 500px :) I know tables are abit old fashioned but email clients can be difficult to predict and tables seem to delay reliably.

    e.g.
    <cfoutput>
    <h2>New Suggestions:</h2>
    <table width="500px">
    <tr><td width="100px">Name:</td><td width="400px">#name#</td></tr>
    <tr><td>Comments</td><td>#comments#</td></tr>
    </table>

    etc...