0
string strTheBody = @"First Name: " + tbFirst.Text + "\nLast Name: " + tbLast.Text + "\nAddress 1: " + tbAdd1.Text + "\nAddress 2: " + tbAdd2.Text + "";
strTheBody += @"\nCity: " + tbCity.Text + "\nState: " + ddlTechState.SelectedValue + "\nZip Code: " + tbZip.Text + "\nDOB: " + tbDOB.Text + "\nEmail Address: " + tbEmail.Text + "";
strTheBody += @"\nLast Doctor visited: " + ddlTechProvider.SelectedValue + "\nIssue: " + ddlTechIssues.SelectedValue + "\n\nComments: " + HttpUtility.HtmlEncode(tbComments.Text) + "";

MailMessage mmSendEmail = new MailMessage();
mmSendEmail.To.Add("myemail@myweb.com");
mmSendEmail.From = new MailAddress(tbEmail.Text);
mmSendEmail.Subject = "Contacting about " + ddlTechIssues.SelectedValue;
mmSendEmail.Body = strTheBody;

SmtpClient scSend = new SmtpClient("mysmtp.myisp.com");
scSend.Send(mmSendEmail);

Sends the email like this:

First Name: first
Last Name: last
Address 1: my address 1
Address 2: \nCity: some city
State: NV
Zip Code: 90320
DOB: 08/08/2013
Email Address: myemail@email.com\nLast Doctor visited: 0
Issue: Result

Comments: This is a comment

How can I resolve the issue with the \n being displayed if the value is empty and when there is an email address.

SearchForKnowledge
  • 3,663
  • 9
  • 49
  • 122

1 Answers1

2

@ symbol means to read that string literally, and don't interpret control characters

I suggest using StringBuilder instead, will remove these type of errors and makes your code generally a lot more readable - in terms of formatting the email anyway.

Community
  • 1
  • 1
horHAY
  • 788
  • 2
  • 10
  • 23