I was doing an SMTP email that will send the order details to the customer email after the purchase. I had successfully sent it to the customer but the format is a little weird.
Below is the output it sends to the customer email.
Your order is successful!
------------------------------------------------
Order ID : Order20465230820207quiw< br />Order Date : 8/30/2020< br />Send To : 81,JALAN KENARI MERAH 8
<br /> Kedah< br /> 05200< br />Grand Total : 499< br />< br />< br />Thank You for purchasing with us!
But it expects it to format like this :
Your order is successful!
------------------------------------------------
Order ID : Order20465230820207quiw
Order Date : 8/30/2020
Send To : 81,JALAN KENARI MERAH 8
Grand Total : 499
Thank You for purchasing with us!
Here is the code:
lblmail.Text = "Your order is succesful! <br />" +
"------------------------------------------------ <br />" +
"Order ID : " + Session["OrderID"].ToString() + "< br />" +
"Order Date : " + Session["orderDate"].ToString() + "< br />" +
"Send To : " + Session["address"].ToString() + "< br />" +
" " + Session["state"].ToString() + "< br />" +
" " + Session["zipcode"].ToString() + "< br />" +
"Grand Total : " + Session["GrandTotal"].ToString() + "< br />" +
"< br />< br />Thank You for purchasing with us!" ;
Do note that I had enabled the HTML is the email body with this code:
MailMessage mm = new MailMessage();
mm.IsBodyHtml = true;
What is the problem here? The code seems to be fine but the output is not what I expected.
确保您的 HTML 标签编写正确“< br />”删除空格,这样您就可以确保服务器不会将其作为文本发送。
< br /> To this <br/>
You need to add HTML insted of normal text
Code
var htmlContent ="<!DOCTYPE html>
<html>
<body>
<h3><p>Your order is successful!</p></h3>
<p>----------------------------------</p>
<p>Order ID : Order20465230820207quiw</p>
<p>Order Date : 8/30/2020</p>
<p>Send To : 81,JALAN KENARI MERAH 8</p>
<p>Grand Total : 499</p>
<p>Thank You for purchasing with us!</p>
</body>
</html>";
using (MailMessage mm = new MailMessage())
{
mm.Body = htmlContent;
mm.IsBodyHtml = true;
}
It's working fine with your mail functionality
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.