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: 2593
  • Last Modified:

CDOSYS, TextBody - add several variables with text and format

Hi,

I'm working on a form using CDOSYS, what I need to do is to be able to send several variables with text and line breaks using  "TextBody", full code below.

All of the asp form samples I have seen use examples such as: myMail.TextBody="This is a message."

Though I need something like this: myMail.TextBody="Message: EmailQuery \n<br> Age: EmailAge \n<br> Nationality: EmailNationality", etc

So that the resulting email would be nicely formatted as:

Message: contents of EmailQuery variable
Age: contents of EmaiAge variable
Nationality: contents of EmailNationality variable

Can someone help?

Thanks,

Al


This is the code I have:
<%

' email values to set in form
'--------------------------------
'  EmailName
'  EmailSurname
'  EmailSenders
'  EmailSubject
'  EmailQuery
'  EmailAge
'  EmailNationality


' set up email values
EmailName=request("EmailName") ' required
EmailSurname=request("EmailSurname")
EmailSenders=request("EmailSenders") ' required
EmailSubject=request("EmailSubject") ' required
EmailQuery=request("EmailQuery") ' required
EmailAge=request("EmailAge")
EmailNationality=request("EmailNationality")

if EmailName="" then
     response.Write("<html><body>Your first name is required<br><br><a href='javascript:history.back()'>« go back</a></body></html>")
     response.End
end if

if EmailSenders="" then
     response.Write("<html><body>Your email is required<br><br><a href='javascript:history.back()'>« go back</a></body></html>")
     response.End
end if

if EmailSubject="" then
     response.Write("<html><body>Please indicate the subject of your message<br><br><a href='javascript:history.back()'>« go back</a></body></html>")
     response.End
end if

if EmailQuery="" then
     response.Write("<html><body>Please write your query<br><br><a href='javascript:history.back()'>« go back</a></body></html>")
     response.End
end if


Set myMail=CreateObject("CDO.Message")
myMail.Subject = EmailSubject
myMail.From = EmailName & "<" & EmailSenders & ">"
myMail.To = "me@mydomain.com"
myMail.Cc = "him@hisdomain.com"
myMail.TextBody = EmailQuery
myMail.Send
set myMail=nothing
 

' show thankyou page
if not request("thanksPage")="" then
     response.Redirect(request("thanksPage"))
else
     response.write("<html><body>Message sent.</body></html>")
end if    
response.End

%>
0
myrepublic
Asked:
myrepublic
  • 4
  • 3
  • 2
2 Solutions
 
nurbekCommented:
use vbCrlf

 myMail.TextBody="Message: EmailQuery " & vbCrlf & "Age: EmailAge" & vbCrlf &  "Nationality:"
0
 
kevp75Commented:
correct, though if you set the content type of the emails to HTML.

if you change myMail.TextBody to myMail.HTMLBody
0
 
myrepublicAuthor Commented:
Hi, thanks for you help.

I have tried this:

Set myMail=CreateObject("CDO.Message")
myMail.Subject = "Scholarship Application"
myMail.From = EmailName & "<" & EmailSenders & ">"
myMail.To = "me@mydomain.com"
myMail.Cc = "him@hisdomain.com"
myMail.HTMLBody="Name: EmailName " & vbCrlf & "Address: EmailAddress" & vbCrlf &  "Senders email: EmailSenders" & vbCrlf &  "Nationality: EmailNationality" & vbCrlf &  "Age: EmailAge"

myMail.Send
set myMail=nothing

This is the output in the email:

Name: EmailName Address: EmailAddress Senders email: EmailSenders Nationality: EmailNationality Age: EmailAge

No formatting and it's not printing the values - only the variable name.

Any ideas?

Thanks,

Al
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
nurbekCommented:
if you use want to sen hhtml format then use HTMLBody

myMail.HTMLBody="Name: EmailName " & "<br>" & "Address: EmailAddress" & "<br>" &  "Senders email: EmailSenders" & "<br>" &  "Nationality: EmailNationality" & "<br>"&  "Age: EmailAge"

if you want to sent text format then use TextBody

myMail.TextBody="Name: EmailName " & vbCrlf & "Address: EmailAddress" & vbCrlf &  "Senders email: EmailSenders" & vbCrlf &  "Nationality: EmailNationality" & vbCrlf &  "Age: EmailAge"

0
 
myrepublicAuthor Commented:
Thanks Nurbek, That's helped with the formatting, though the field values are still not being sent:

This is the email output:

Name: EmailName
Address: EmailAddress
Senders email: EmailSenders
Nationality: EmailNationality
Age: EmailAge

Should be:

Name: A Name
Address: an@email.com
Senders email: senders@email.com
Nationality: British
Age: 26

etc
0
 
kevp75Commented:
k..change this:
Set myMail=CreateObject("CDO.Message")
myMail.Subject = "Scholarship Application"
myMail.From = EmailName & "<" & EmailSenders & ">"
myMail.To = "me@mydomain.com"
myMail.Cc = "him@hisdomain.com"
myMail.HTMLBody="Name: EmailName " & vbCrlf & "Address: EmailAddress" & vbCrlf &  "Senders email: EmailSenders" & vbCrlf &  "Nationality: EmailNationality" & vbCrlf &  "Age: EmailAge"

to this:
Set myMail=CreateObject("CDO.Message")
myMail.Subject = "Scholarship Application"
myMail.From = EmailName & "<" & EmailSenders & ">"
myMail.To = "me@mydomain.com"
myMail.Cc = "him@hisdomain.com"
myMail.HTMLBody="Name: " & EmailName & "<br />Address: " & EmailAddress & "<br />Senders email: " & EmailSenders & "<br />Nationality: " & EmailNationality & "<br />Age: " & EmailAge
0
 
kevp75Commented:
problem was you had your variables enclosed in the quotes with your fields, so it was send the name of variable instead of the variable.

If you notice, all I did was move them to the outside of the quotes (thus the values will show and not just the name of the variable) and added in <br /> (which is html line-break)
0
 
myrepublicAuthor Commented:
nice one Kev, that worked!
0
 
kevp75Commented:
i'm a bit confused....(not that I really mind, but...)  why the split?  the answer you accepted of his is the exact same thing that I posted in my first post?

like I said, I don't really care...just curious


(p.s. thanks for the grade!  :) )
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now