Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting variable output in an email... 1

Status
Not open for further replies.

marvelisticme

Technical User
Feb 3, 2005
70
US
Hi, all :)

I have an asp that sends email notices to various employees upon submit and I have a request for some of the text in the email body to be bolded so that it is easier to spot. Is there a way to do this? I didn't create these pages and am not versed in this type of programming, but have been given the task of maintaining the pages :) Thanks for any help!


Mail.AddAddress "anybody@anywhere.com"
Mail.Subject = "W2 Copy Request recieved from " &strUsername

'<!--- Begin Ludicrously Huge Message Body --->
Mail.Body = "W2 Copy Request received from: " &strUsername & vbCrLf & vbCrLf & "Employee Name: " &strEmployee & vbCrLf & vbCrLf & "SSN: " &strSSN & vbCrLf & vbCrLf & "Comments: " &strComments & vbCrLf & vbCrLf & "Company: " &strCompany & vbCrLf & vbCrLf & "----W-2 Copy Request----" & vbCrLf & vbCrLf & "W-2 Year" &strW2_year & vbCrLf & vbCrLf & "Delivery Options: " &strW2_options & VbCrLf & VbCrLf & "Address: " &strW2_street & vbCrLf & "City: " &strW2_city & vbCrlf & "State: " &strw2_state & vbCrLf & "Zip: " &strW2_zip & vbCrLf & vbCrLf
Mail.Send

If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
 
There should be more relevant code above this including a line like: Set Mail = Server.CreateObject("something here")

Can you post that too please.


In a nutshell, if the email is currently built as a text email then you can't bold bots. To do that you need to change the type of the email to HTML for example.

Post the code I mentioned and it will help us show you how to do that.

Tony
[blue]________________________________________[/blue]
 
Sorry! Shows how much I know, huh? ;-)

'<!--- Begin Mail Creation --->
Set Mail = Server.CreateObject("Persits.Mailsender")
Mail.Host = strHost
Mail.From = "Global User"
Mail.FromName = strUsername
Mail.AddAddress "test1@test11.com"
Mail.Subject = "W2 Copy Request recieved from " &strUsername

'<!--- Begin Ludicrously Huge Message Body --->
Mail.Body = "W2 Copy Request received from: " &strUsername & vbCrLf & vbCrLf & "Employee Name: " &strEmployee & vbCrLf & vbCrLf & "SSN: " &strSSN & vbCrLf & vbCrLf & "Comments: " &strComments & vbCrLf & vbCrLf & "Company: " &strCompany & vbCrLf & vbCrLf & "----W-2 Copy Request----" & vbCrLf & vbCrLf & "W-2 Year" &strW2_year & vbCrLf & vbCrLf & "Delivery Options: " &strW2_options & VbCrLf & VbCrLf & "Address: " &strW2_street & vbCrLf & "City: " &strW2_city & vbCrlf & "State: " &strw2_state & vbCrLf & "Zip: " &strW2_zip & vbCrLf & vbCrLf
Mail.Send

If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If
 
I did know that some types of email don't support text formatting, but I couldn't figure out how to tell what this particular code was capable of.

Thanks so much for any help!
 
I may very well be misunderstanding the FAQ, but it appears that it only explains how to format typed text within quotes. Is there a way to format the output of variables, which are not between quotes? This is VBscript stuff.

Thanks!
 
What the heck is the output of variables?

Just concat your formatting codes into the text of the message.

For example if you were using HTML then somethng like this:
myString = "Company:<b>" & strCompany & "</b>" & vbCrLf

 
That's what I thought, but I'm getting a VBScript error and the page cannot be displayed...

Error Type:
Microsoft VBScript compilation (0x800A03EA)
Syntax error
/gis/w2.asp, line 146, column 100

Line 146 is...
Mail.Body = "W2 Copy Request received from: " &strUsername & vbCrLf & vbCrLf & "Employee Name: "<b> &strEmployee </b>& vbCrLf & vbCrLf & "SSN: " &strSSN & vbCrLf & vbCrLf & "Comments: " &strComments & vbCrLf & vbCrLf & "Company: " &strCompany & vbCrLf & vbCrLf & "----W-2 Copy Request----" & vbCrLf & vbCrLf & "W-2 Year" &strW2_year & vbCrLf & vbCrLf & "Delivery Options: " &strW2_options & VbCrLf & VbCrLf & "Address: " &strW2_street & vbCrLf & "City: " &strW2_city & vbCrlf & "State: " &strw2_state & vbCrLf & "Zip: " &strW2_zip & vbCrLf & vbCrLf

From what I can determine, the html formatting can only be used between quotes. I'm hoping I'm wrong. I tried having <html><body></body></html> around the text, but this gives the same error :-/
 
Ok, put the <html><body></body></html> back around it and use <br> instead of vbCrLf. Also before you send, put this line in:

Mail.IsHTML = True

So your body could look like:
Code:
Mail.Body = "<html><body>W2 Copy Request received from: " & strUsername & "<br><br>Employee Name:<b>" &strEmployee & "</b><br><br>SSN: " &strSSN & "<br><br>Comments: " & strComments & "<br><br>Company: " & strCompany & "<br><br>"----W-2 Copy Request----<br><br>W-2 Year" & strW2_year & " <br><br>Delivery Options: " & strW2_options & " <br><br>Address: " & strW2_street & " <br><br>City: " & strW2_city & " <br><br>State: " & strw2_state & " <br><br>Zip: " & strW2_zip & " <br><br></body></html>
Mail.IsHTML = True
 
whooops ... remove the double quotes before the ----W-2. It shouldn't be there.
 
Ok, done, but got the following error...

Error Type:
Microsoft VBScript compilation (0x800A0409)
Unterminated string constant
/gis/w2.asp, line 146, column 494

Should the quotes at the beginning be after <body>, and/or should there be quotes at the end of the string?

Thanks you so much for taking the time to help me!!!
 
That's it...missed the quotes at the end of the string. My bad man. Add those and you should be fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top