Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 612
  • Last Modified:

How do I insert carriage returns?

Hi Experts,

I found this script from EE:

EmailBodyEdit = Replace(Request("EmailBody"), vbcrlf, "<br>")

I used it with this script:

<%

  IF Request("EmailBody")="" THEN
    strBody = "<HTML><BODY>"
  ELSE
    EmailBodyEdit = Replace(Request("EmailBody"), vbcrlf, "<br>")
    strBody = "<HTML><BODY>" & EmailBodyEdit  & "<br><br>"
  END IF

  strBody = strBody & "<TABLE border='1' align='center' style='border-collapse: collapse;border: 1px solid black;' cellspacing='2' width='98%'>"  
  strBody = strBody & "<tr style='border: 1px solid black;'>"
  strBody = strBody & "<td style='border: 1px solid black;' width='2%' align='center'>"
  strBody = strBody & "<FONT face='arial' size='2'><b>#</b></FONT>"
  strBody = strBody & "</td>"

  strBody = strBody & "<td style='border: 1px solid black;' width='6%' align='center'>"
  strBody = strBody & "<FONT face='arial' size='2'><b>Shipment #</b></FONT>"
  strBody = strBody & "</td>"

  strBody = strBody & "<td style='border: 1px solid black;' width='8%' align='center'>"
  strBody = strBody & "<FONT face='arial' size='2'><b>Container</b></FONT>"
  strBody = strBody & "</td>"

  strBody = strBody & "<td style='border: 1px solid black;' width='4%' align='center'>"
  strBody = strBody & "<FONT face='arial' size='2'><b>Pallets</b></FONT>"
  strBody = strBody & "</td>"

  strBody = strBody & "<td style='border: 1px solid black;' width='6%' align='center'>"
  strBody = strBody & "<FONT face='arial' size='2'><b>Ship From</b></FONT>"
  strBody = strBody & "</td>"

  strBody = strBody & "<td style='border: 1px solid black;' width='28%' align='center'>"
  strBody = strBody & "<FONT face='arial' size='2'><b>Issue To</b></FONT>"
  strBody = strBody & "</td>"

  strBody = strBody & "<td style='border: 1px solid black;' width='12%' align='left'>"
  strBody = strBody & "<FONT face='arial' size='2'><b>Appt. Date Time</b></FONT>"
  strBody = strBody & "</td>"

  strBody = strBody & "<td style='border: 1px solid black;' width='5%' align='center'>"
  strBody = strBody & "<FONT face='arial' size='2'><b>Drop/Stay</b></FONT>"
  strBody = strBody & "</td>"

  strBody = strBody & "<td style='border: 1px solid black;' width='31%' align='center'>"
  strBody = strBody & "<FONT face='arial' size='2'><b>Notes</b></FONT>"
  strBody = strBody & "</td>"

  strBody = strBody & "</tr>"

  WHILE NOT rs.EOF

    strBody = strBody & "<tr style='border: 1px solid black;'>"
    strBody = strBody & "<td style='border: 1px solid black;' width='2%'align='center'>"
    strBody = strBody & "<FONT face='arial' size='2'>" & i & "</b></FONT>"
    strBody = strBody & "</td>"

    strBody = strBody & "<td style='border: 1px solid black;' width='6%' align='center'>"
    strBody = strBody & "<FONT face='arial' size='2'>" & rs("ShipmentNo") & "</FONT>"
    strBody = strBody & "</td>"

    strBody = strBody & "<td style='border: 1px solid black;' width='8%' align='center'>"
    strBody = strBody & "<FONT face='arial' size='2'>" & rs("ContID") & "</FONT>"
    strBody = strBody & "</td>"

    strBody = strBody & "<td style='border: 1px solid black;' width='4%' align='center'>"
    strBody = strBody & "<FONT face='arial' size='2'>" & rs("Pallets") & "</FONT>"
    strBody = strBody & "</td>"

    strBody = strBody & "<td style='border: 1px solid black;' width='6%' align='center'>"
    strBody = strBody & "<FONT face='arial' size='2'>" & rs("ShipFrom") & "</FONT>"
    strBody = strBody & "</td>"

    strBody = strBody & "<td style='border: 1px solid black;' width='28%' align='left'>"
    strBody = strBody & "<FONT face='arial' size='2'>" & rs("IssueTo") & "</FONT>"
    strBody = strBody & "</td>"

    strBody = strBody & "<td style='border: 1px solid black;' width='12%' align='left'>"
    strBody = strBody & "<FONT face='arial' size='2'>" & rs("ApptDateTime") & "</FONT>"
    strBody = strBody & "</td>"

    strBody = strBody & "<td style='border: 1px solid black;' width='5%' align='center'>"
    strBody = strBody & "<FONT face='arial' size='2'>" & rs("DropOrStay") & "</FONT>"
    strBody = strBody & "</td>"

    strBody = strBody & "<td style='border: 1px solid black;' width='31%' align='center'>"
    strBody = strBody & "<FONT face='arial' size='2'>" & rs("ExternalNotes") & "</FONT>"
    strBody = strBody & "</td>"

    strBody = strBody & "</tr>"

    i = i + 1

    rs.MoveNext

  WEND

  strBody = strBody & "</TABLE></BODY></HTML>"

%>

  ' Call JMail to handle emailing

  '*************************************************
  '*                                               *
  '*   Produced by Dimac                           *
  '*                                               *
  '*   More examples can be found at                *
  '*   http://tech.dimac.net                       *
  '*                                               *
  '*   Support is available at our helpdesk        *
  '*   http://support.dimac.net                    *
  '*                                               *
  '*   Our main website is located at              *
  '*   http://www.dimac.net                        *
  '*                                               *
  '*************************************************

  Set jmail = Server.CreateObject("JMail.Message")

  jmail.AddRecipient strTo
  jmail.AddRecipient strFrom

  jmail.From = strFrom
      
  jmail.Subject = strSubject

  jmail.HTMLBody = strBody

  jmail.Send("mailhost.chep.com")


When the email is sent, the carriage returns do not show. The text is still in one line. Why?

Thanks
0
indyng
Asked:
indyng
1 Solution
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
Because you're not using vbCrLf - put that at the end of every line you want a carraige return.
0
 
Saqib KhanSenior DeveloperCommented:
jmail component Must have a HTML property, you are sending Plain Emails with jmail, look into their Documentation to see how to send HTML based emails.
0
 
Saqib KhanSenior DeveloperCommented:
@ leew  VbCrlf will not help, because questioner wants to send HTML based emails not the plain text, as you can see he/she is using Tables for the email Body.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
indyngAuthor Commented:
leew,

This would not make sense because the user would have to put the vbCrlf

Thanks
0
 
indyngAuthor Commented:
jmail.HTMLBody = strBody

jmail component does have a HTML property
0
 
indyngAuthor Commented:
I think the problem is the carriage return used in the text area does not show up in the URL string


http://camisms01/intermodal/shipment_tracker/EmailPreview.asp?SendEmail=1&EmailTo=rng77@rogers.com&EmailBody=testtestttestest

0
 
Saqib KhanSenior DeveloperCommented:
replace textarea's Vbcrlf with <BR>

say txt1 is the variable holding textarea text then do this

txt1 = replace(txt1, VbCrlf, "<br>")
0
 
indyngAuthor Commented:
I have this function:

function MailTo()
{
 x=document.EmailPreview

 if(x.RecipientEmail.options[x.RecipientEmail.selectedIndex].value=="")
 {
 alert("Please select recipient email address")
 return false;
 }
 else
 {
 document.location.href= 'EmailPreview.asp?SendEmail=1&EmailTo=' + x.RecipientEmail.options[x.RecipientEmail.selectedIndex].value + '&EmailBody=' + x.EmailBody.value
 }
}

Do I need to use Server.HtmlEncode?

Thanks
0
 
inviserCommented:
try this instead:

EmailBodyEdit = Replace(Request("EmailBody"), chr(13) & chr(10), "<br>")
0
 
indyngAuthor Commented:
inviser,

Not working. I think the problem is the vbCrlf is not part of the query string.

See,

http://camisms01/intermodal/shipment_tracker/EmailPreview.asp?SendEmail=1&EmailTo=rng77@rogers.com&EmailBody=testtestttestest

Although the text area has:

test
test
test
test
0
 
Saqib KhanSenior DeveloperCommented:
its always not a good idea to pass Long text in a query string.

You should Submit your Form with the "Post" method. then it should work.


function MailTo()
{
 x=document.EmailPreview

 if(x.RecipientEmail.options[x.RecipientEmail.selectedIndex].value=="")
 {
 alert("Please select recipient email address")
 return false;
 }
 else
 {
    x.submit()
 }
}
0
 
CWS (haripriya)Commented:
Best think is after the break "<br>" you put a space.That is,  &nbsp;

Try this and let me know.
0
 
kevp75Commented:
adilkhan is correct, not a real good idea to send all that text in a querystring.  Best to use the 'post' method of your form, then do your replacing
0
 
indyngAuthor Commented:
I resolved this by inserting <br> using a javascript
0
 
CetusMODCommented:
Closed, 500 points refunded.
CetusMOD
Community Support Moderator
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now