Skip to main content
Inspiring
April 15, 2011
Answered

Odd cfmail subject problem

  • April 15, 2011
  • 2 replies
  • 1251 views

Now the latest in my coldfusion adventures!

I have a variable field that I put in my email subject line:

<cfset email_subject = "A leave request has been deleted by #User_Name# - FYI Only" />

<cfmail

     to=email@email.com

     subject="#email_subject#" type="html">

Dumping User_Name shows that it is:  "Bob Marley", with only 1 space between the first and last name.

Dumping the email_subject filed prior to sending the email shows: "Leave Request Deleted By Bob Marley - FYI Only"

However, when the email arrives, an additional 17 spaces have been added between the names!

"Leave Request Deleted By Bob                  Marley - FYI Only"

I've even tried Trim to no avail.  And type="text", "plain" and simply omitted, make no difference in the subject line.

Any suggestions?

    This topic has been closed for replies.
    Correct answer Reed_Powell-ttnmOb

    So what you are saying is if you do this:

    <pre><cfoutput>#User_Name#</cfoutput></pre>

    It does not show the extra spacing?

    I mean, forget about the CFMAIL bit for the time being, just output the variable.

    --

    Adam


    Do what Adam suggested.  Put the output of the var between a pair of delimiters such as [] so that you can visually see just what is in the var.  Try outputting its length as well, just in case there are any non-printable characters in it - does the length match what you see visually on the screen?  Also try viewing that result via VIEW SOURCE.  Finally what happens if you include that same var's contents in the body of the email?  As someone pointed out, the SUBJ line is not HTML formatted.

    -reed

    2 replies

    Inspiring
    April 17, 2011

    Dumping User_Name shows that it is:  "Bob Marley", with only 1 space between the first and last name.


    Well it would.  Browsers render any run of whitespace characters as a single space.  This is just standard default behaviour.

    What if you ourput it between PRE tags?

    --

    Adam

    Inspiring
    April 16, 2011

    Does the same thing happen if you hard code the value?

    sockerdadAuthor
    Inspiring
    April 18, 2011

    If the subject line is hard-coded as "Leave Request Deleted By Bob Marley - FYI Only", the spacing is perfect.  The problem comes when trying to use the variable including the name.

    And no, <pre> didn't work.  I failed to mention that I had previously tried that.

    I also parsed the name into two separate fields with the same result.

    Inspiring
    April 18, 2011

    So what you are saying is if you do this:

    <pre><cfoutput>#User_Name#</cfoutput></pre>

    It does not show the extra spacing?

    I mean, forget about the CFMAIL bit for the time being, just output the variable.

    --

    Adam