How to insert a line feed when emailing from a web form using Visual Basic
Posted on 2006-10-25
I have a web form which collects data from various text fields and sends it via SMTP to a single recipient. The fields are all in the from msg.Body. Everything works fine but the resultant email is difficult to read because all of information in the email ends up on one or two lines. How can I insert line breaks so that the resultant email is more easily read?
Thanks in advance...
Sample VB Code behind the "Send" button.
Partial Class Registration
Protected Sub btnSend_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSend.Click
Dim fromAddress As New MailAddress("email@example.com")
Dim toAddress As New MailAddress("firstname.lastname@example.org")
Dim msg As New MailMessage(fromAddress, toAddress)
msg.Subject = " Test MAIL MESSAGE"
msg.Body = "First Name:" + " " + txtFirstName.Text.Trim() + " " + _
txtLastName.Text.Trim() + ", " + txtMI.Text.Trim() _
"Address:" + " " + txtAddress + "City:" + " " + txtCity.Text _
' More code like above
msg.IsBodyHtml = True
Dim mailSender As New System.Net.Mail.SmtpClient
mailSender.Host = "mail.hostname.com"
lblMessage.Text = "Message Sent!"
Catch ex As Exception
lblMessage.Text = ex.Message