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> <b>Name2:</b> <xsl:value-of select="$Name" /> </p> <p> <b>Telephone Number:</b> <xsl:value-of select="$TelephoneNumber" /> </p> <p> <b>Email:</b> <a 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?
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.
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! :)
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.
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>
<b>Name2:</b>
<xsl:value-of select="$Name" />
</p>
<p>
<b>Telephone Number:</b> <xsl:value-of select="$TelephoneNumber" />
</p>
<p>
<b>Email:</b> <a 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?
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
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
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
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">
<p>
<b>Name2:</b>
<xsl:value-of select="$Name" />
</p>
<p>
<b>Telephone Number:</b> <xsl:value-of select="$TelephoneNumber" />
</p>
<p>
<b>Email:</b> <a 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)" />
Long winded and not all that pretty but its works for now which will do.
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 < (and not the ">") so it doesn't get recognised as xml anymore.
is working on a reply...