I have contact form which is sending email.
But if I type a long message in the text area and after clicking submit, in my email this message displaying in single line.
e.g if开发者_Python百科 i type that in Message text area:
My super Mesasge
My Mesasge Mesasge
From Test.
In my email box it will be like:
My super Mesasge My Mesasge Mesasge From Test.
Why the formatting("/r/n") getting lost and how could i keep the formatting of that message?
UPDATE: I used AntiXSS.4.0.1 e.g: model.Message: "sdfsdf\r\nsdfsdf\r\nsdfsdfsdafsdfa"
I did that:
model.Message = model.Message.Replace("\r\n", "<br />");
//result: model.Message="sdfsdf<br />sdfsdf<br />sdfsdfsdafsdfa"
Than:
model.Message = Sanitizer.GetSafeHtmlFragment(model.Message);
//result: model.Message="sdfsdf<br>\r\nsdfsdf<br>\r\nsdfsdfsdafsdfa"
So why Sanitizer.GetSafeHtmlFragment added \r\n back? and it is changed also <br />
to <br>
The only thing I can think of, is that your email format is in HTML, so the the NewLine
should be converted in <p></p>
tag or <br />
This will depend on how you are sending the email. If you use HTML (message.IsBodyHtml
) then you need to replace \r\n
with <br/>
when populating the message.Body
.
精彩评论