CDOSYS email - create hyperlink in body?

B

Beefminator

Hello,

How can you create a hyperlink in the HTML body of CDOsys email? Line 7
is a link for yahoo.com, but the asp page does not work.

Set objMessage = CreateObject("CDO.Message")
objMessage.Subject ="Test Page - File upload"
objMessage.Sender = "" & Request.Form("email1") & ""
objMessage.To ="(e-mail address removed)"
objMessage.HTMLBody = "Email: " & Request.Form("email1") & vbCrLf & _
"Confirmation #: " & Request.Form("ConfirmID") & vbCrLf & _
"<a href="http://yahoo.com.com/">yahoo</a>" & vbCrLf & _
"FileName: " & Request.Form("file1") & vbCrLf & _
"Name: " & Request.Form("Name") & vbCrLf

Thanks,
Jason
 
A

Aaron Bertrand [SQL Server MVP]

" is a string delimiter. When you say myString = "foo"bar" the string ends
at the second ", then VBScript will crap out due to a syntax error, because
it doesn't understand why you have added more text after you have closed the
string.

Usual workarounds:

double them up to escape them :
MyString = "<a href=""http://www.foo.com/"">"
use single quotes :
MyString = "<a href='http://www.foo.com/'>"
don't use them, since they are only necessary if someone is validating the
document :
MyString = "<a href=http://www.foo.com/>"

(Typically, "does not work" is not enough information for us to figure this
out. In the future, please define "does not work" by providing a specific
error message and highlighting the relevant line in your code.)
 
B

Beefminator

Hey Brian,

That was it. I am still a young grasshopper. I appreciate your time.

Jason
 
B

Beefminator

Hey Brian,

That was it. I am still a young grasshopper. I appreciate your time.

Jason
 
B

Beefminator

In the HTMLbody of CDO message, can field be added in hyperlink
address? I can't get this to work:

"<a href="""" & Request.Form(""file1"") & """">U-1162 form</a><br>" &
vbCrLf & _

Thanks,
Jason
 
M

Mike Brind

Beefminator said:
In the HTMLbody of CDO message, can field be added in hyperlink
address? I can't get this to work:

"<a href="""" & Request.Form(""file1"") & """">U-1162 form</a><br>" &
vbCrLf & _

You should only double up on quotes if you want them to appear as part
of a literal string.

"<a href=""" has an opening double quote to tell the parser that
everything that follows is part of a string. Then there is the doubled
double quote that tell the parser to parse a literal double quote,
followed by a double quote to close the string (3 in total - not 4).
Then you concatenate the value of a variable - Request.Form("file1").
Since you have broken out of the string literal at this point, you
should not be doubling quotes around file1.

After the second ampersand (&), you start a new string literal with a
double quote, and immediately want to include a literal double quote,
so you need to double it again. That's 1 for opening the string, and 2
for the double quote, which totals 3 double quotes - not 4 as you have.

Here's how it should appear:

"<a href=""" & Request.Form("file1") & """>U-1162 form</a><br>" &
vbcrlf & _

Alternatively, you can replace the doubled double quote with the chr()
function (34 is the ascii character for a double quote):

"<a href=" & chr(34) & Request.Form("file1") & chr(34) & ">U-1162
form</a><br>" & vbcrlf & _

Hope this make sense.
 
B

Beefminator

Beautiful Mike..just beautiful..you have showed me the light...

Thanks again for your time,
Jason
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top