I've built a Contact Form user control for a site I'm building with Umbraco and I have a few custom parameters that allow for customization of the email sent to the company.
The macro looks like this when inserted into a template:
<umbraco:Macro DestinationEmail="[email protected]" Subject="Corporate Website Contact" EmailMessageFormatString="Name: {0}%0D%0ACompany: {1}\r\nEmail: {2}\r\nPhone: {3}\r\n\r\nMessage:\r\n---------------------\r\n{4}\r\n" ThankYouMessageString="Thank you. Your message has been sent successfully. We will get back to you within 2 business days." Alias="ContactForm" runat="server"></umbraco:Macro>
I'm trying to figure out how I can insert a new line code into the EmailMessageFormatString parameter so that the email sent has some formatting and its not all run together. I suppose I could make the email html formatted and use markup, but this was a question I could not find an answer to.
Any thoughts? Can a new line be encoded into the EmailMessageFormatString?
If not I would use a special textual marker in the EmailMessageFormatString like EmailMessageFormatString="Name: {0}%0D%0ACompany: {1}<<nl>>Email:
{2}\r\nPhone: {3}<<nl>>Message:<<nl>>---------------------<<nl>>{4}<<nl>>"
Then, before the email is sent I would string replace the marker
New line characters are respected in a non-html email. If this still isn't working then double check your not already trying to send the email as html.
To expand on my previous post, your Macro would read the file from the filesystem and you could edit it through the Umbraco GUI using Tim G's config tree package.
Adding newlines in macro parameters
Hello,
I've built a Contact Form user control for a site I'm building with Umbraco and I have a few custom parameters that allow for customization of the email sent to the company.
The macro looks like this when inserted into a template:
<umbraco:Macro DestinationEmail="[email protected]" Subject="Corporate Website Contact" EmailMessageFormatString="Name: {0}%0D%0ACompany: {1}\r\nEmail: {2}\r\nPhone: {3}\r\n\r\nMessage:\r\n---------------------\r\n{4}\r\n" ThankYouMessageString="Thank you. Your message has been sent successfully. We will get back to you within 2 business days." Alias="ContactForm" runat="server"></umbraco:Macro>
I'm trying to figure out how I can insert a new line code into the EmailMessageFormatString parameter so that the email sent has some formatting and its not all run together. I suppose I could make the email html formatted and use markup, but this was a question I could not find an answer to.
Any thoughts? Can a new line be encoded into the EmailMessageFormatString?
Thanks,
Jason
Hi Jason,
I'm unclear, does the above approach work?
If not I would use a special textual marker in the EmailMessageFormatString like EmailMessageFormatString="Name: {0}%0D%0ACompany: {1}<<nl>>Email: {2}\r\nPhone: {3}<<nl>>Message:<<nl>>---------------------<<nl>>{4}<<nl>>"
Then, before the email is sent I would string replace the marker
New line characters are respected in a non-html email. If this still isn't working then double check your not already trying to send the email as html.
Yea, neither of the newline attempts in my original question worked.
The newline replacement idea is a good one. I tested that and it works great. Thanks for the response.
Should those "\r\n"s work in a macro param? Do they need to be encoded?
I'm not too sure about passing "\r\n" as a macro param. It should have worked as it's the same as Environment.NewLine.
Hi guys,
Isn't this something similar... http://our.umbraco.org/forum/developers/xslt/3240-dreaded-rn-has-re-appeared?p=1
No real solution currently, as people are still trying to lock down the issue
Cheers,
/Dirk
Yea, I'm now noticing wierd /r/n appearing randomly in the macro params when I insert in into a richtext editor.
Can I suggest that you put your email template in a configuration file and pass the filename as the parameter to the macro?
IMHO it makes your template code a lot more readable!
To expand on my previous post, your Macro would read the file from the filesystem and you could edit it through the Umbraco GUI using Tim G's config tree package.
I'll take a look at the config tree package and see if I can get that to work.
Thanks
BTW, the config file solution worked like a charm. Thanks Darren!
is working on a reply...