SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2006
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Text Area Not recognizing Line-breaks

    Hi all,

    I have a little email blast form with a text area for personal messages, but when sent, it doesn't recognize the natural line-breaks... it shows up as one line.

    I've seen a function around, but it doesn't seem to work within my code.
    I'm not a .NET person in the least bit!
    How can i either integrate this into what i have, or how can i get the text area to recognize natural line-breaks?

    Here's what i found on the net:

    Code:
    function AddHTMLBreaks(varString)
        varString = Replace(varString,vbCRLF,"<br>")
        varString = Replace(varString,vbLF,"<br>")
        varString = Replace(varString,vbCR,"<br>")
        AddHTMLBreaks= varString
    end function
    And here's what i'm working with:

    Code:
    dim strAddr as String
    dim replyTo as String
    dim strSubject as String
    dim strName as String
    dim strMsg as String
    dim strFrom as String
    dim strEmails as String
        
    Sub Page_Load(sender as Object, e as EventArgs)
    	If Not Page.IsPostBack then
    		pnlForm.Visible = True
    	End If
    End Sub
    
    	
    Sub btnSubmit_Click(sender as Object, e as EventArgs)
    	
    	If Page.IsValid then
    	
    	strAddr = Trim(Request.form("user_email"))
    	if strAddr <> "" then
    		replyTo = strAddr
    	end if
        
    	strEmails = Request.form("recieveing_emails")
    	strSubject = Request.form("user_subject")
    	strName = Request.form("user_name")
    	strFrom = Request.form("from_email")
    	strMsg = Request.form("question")
    	
        Dim objEmail as New MailMessage()
    	    With objEmail
    		  .BodyFormat = MailFormat.Html
    	      .Bcc = strEmails
    	      .From = strFrom
    	      .Headers.Add("Reply-To", replyTo)
    	      .Subject = strSubject
    	      .Body = strMsg + "<br><br><div style='width:640px;'>HTML Content</div>"
    		End With
    				
    	   SmtpMail.SmtpServer  = "127.0.0.1" 
    	try
    		SmtpMail.Send(objEMail)
    	catch exc as Exception
    		lblErrMsg.Text = ("E-mail was not sent because of a server error: " + exc.ToString())
    	End Try
        
    	pnlForm.Visible = False
    	
    	
    	strMsg = replace(strMsg,vbNewline,"<br />")
         
        
        lblAck.Text=("<h2>Thank you. <br />Your email has been sent successfully.</h2>")
        
    End If
    End Sub
    Thanks a million!

  2. #2
    SitePoint Guru
    Join Date
    Nov 2005
    Location
    Norway
    Posts
    715
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Environment.NewLine should work:
    Code:
    Replace(Environment.NewLine, "<br>");
    Also, you should HtmlEncode all the data that you get from the user.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •