Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Peter Duncanson 430 posts 1360 karma points c-trib
    Nov 22, 2010 @ 20:14
    Peter Duncanson
    0

    umbraco.library:SendMail strips away my formatting?!?!

    This one should be dead easy. I'm sending email from XSLT. I build a variable up for my body text and call the function but the email always has all its formatting stripped?

    Rebooted incase it was a caching issue but still there, its as if its completely stripping all the HTML???

              <!-- sumbit the form and thank you -->
              <xsl:variable name="fromMail" select="'[email protected]'" />
              <xsl:variable name="toMail" select="'[email protected]'" />
              <xsl:variable name="subject">Response for: <xsl:value-of select="$formTitle" /></xsl:variable>
              <xsl:variable name="body">
                <p>
                  &lt;b&gt;Name2:&lt;/b&gt;
                  <xsl:value-of select="$Name" />
                </p>
                <p>
                  <b>Telephone Number:</b<xsl:value-of select="$TelephoneNumber" />
                </p>
                <p>
                  <b>Email:</b<href="mailto:{$Email}"><xsl:value-of select="$Email" /></a>
                </p>
                <p>
                  <b>House Number:</b<xsl:value-of select="$HouseNumber" />
                </p>
                <p>
                  <b>Postcode:</b<xsl:value-of select="$Postcode" />
                </p>
                <p>
                  <b>Message:</b<xsl:value-of select="$Message" />
                </p>
                <p>
                  This message was sent from this form: <xsl:value-of select="umbraco.library:NiceUrlFullPath($currentPage/@id)" />
                </p>
              </xsl:variable>
              <xsl:variable name="asHtml" select="'true'" />
              <xsl:value-of select="umbraco.library:SendMail( $fromMail, $toMail, $subject, $body, $asHtml)" />

    Is there a trick I'm missing? Check the source code and there is nothing in there that strips the formatting so whats going on? Anyone else used this with any success?

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Nov 22, 2010 @ 20:29
    Chriztian Steinmeier
    4

    Hi Pete,

    That's because the C# function asks for a string and you're sending a truck load of XML towards it, so the XSLT processor (responsible for delivering the right format) will perform the cast, effectively taking the string-representation of that XML chunk, which is the same as doing <xsl:value-of select="$body" />.

    You need to do the "CDATA-slalom", or escape everything to make sure you end up with a string variable instead of an XML chunk.

    /Chriztian 

  • Peter Duncanson 430 posts 1360 karma points c-trib
    Nov 23, 2010 @ 10:33
    Peter Duncanson
    0

    That my friend is a great reply. I've escaped all the angle brackets and its works a treat. Horrid hack to have to do but makes sense, I'm building up XML and not a "string". Obvious once pointed out. Thanks Chriztian, I had been staring at that one (and swearing loudly) for a few hours! :)

    Pete

  • Hundebol 167 posts 314 karma points
    Nov 23, 2010 @ 10:44
    Hundebol
    0

    Hi Peter,

     

    Maybe you would like to share the working code?

    I know from experience, that sending mails is not always the easiest thing for people, even though it should be as simple as scrathing your.. something.

    best regards,
    Hundebol

  • Peter Duncanson 430 posts 1360 karma points c-trib
    Nov 23, 2010 @ 13:31
    Peter Duncanson
    0

    Good point Hundebol, its nothing fancy I just XML/HTML encode all the angle brackets so its a "string" instead of "xml" to the parser:

      <xsl:variable name="body">
                &lt;p&gt;
                  &lt;b&gt;Name2:&lt;/b&gt;
                  <xsl:value-of select="$Name" />
                &lt;/p&gt;
                &lt;p&gt;
                  &lt;b&gt;Telephone Number:&lt;/b&gt; <xsl:value-of select="$TelephoneNumber" />
                &lt;/p&gt;
                &lt;p&gt;
                  &lt;b&gt;Email:&lt;/b&gt; &lt;a href="mailto:{$Email}"&gt;<xsl:value-of select="$Email" />&lt;/a&gt;
                &lt;/p&gt;
                &lt;p&gt;
                  &lt;b&gt;House Number:&lt;/b&gt; <xsl:value-of select="$HouseNumber" />
                &lt;/p&gt;
                &lt;p&gt;
                  &lt;b&gt;Postcode:&lt;/b&gt; <xsl:value-of select="$Postcode" />
                &lt;/p&gt;
                &lt;p&gt;
                  &lt;b&gt;Message:&lt;/b&gt; <xsl:value-of select="$Message" />
                &lt;/p&gt;
                &lt;p&gt;
                  This message was sent from this form: <xsl:value-of select="umbraco.library:NiceUrlFullPath($currentPage/@id)" />
                &lt;/p&gt;
              </xsl:variable>
              <xsl:variable name="asHtml" select="'true'" />
              <xsl:value-of select="umbraco.library:SendMail( $fromMail, $toMail, $subject, $body, $asHtml)" />

    Long winded and not all that pretty but its works for now which will do.

  • David Verberckmoes 46 posts 77 karma points
    Nov 23, 2010 @ 14:10
    David Verberckmoes
    0

    You can use this tool to HTMLencode the email-body: http://www.opinionatedgeek.com/dotnet/tools/htmlencode/encode.aspx And as a counterpart there is also a decoder: http://www.opinionatedgeek.com/dotnet/tools/htmlencode/Decode.aspx

    Another option (but for rather small texts) is to only encode the "<" into &lt; (and not the ">") so it doesn't get recognised as xml anymore.

    &lt;p>
        &lt;b&gt;Name2:&lt;/b&gt;
        <xsl:value-of select="$Name" />
    &lt;/p>
Please Sign in or register to post replies

Write your reply to:

Draft