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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax error, help please

Status
Not open for further replies.

SteveHigh

Technical User
Jan 17, 2007
158
GB
Hello

I have an online form with the following fields: name, email, business, country, message.

The script stoes the data input into a NS Access database and sends a copy of the site visitor's data to the Webmaster - and a copy to the site visitor himself.

This works, but I have since played about with the code so as to make the copy received by the site visitor more atractive (with my own font, colour, and style).

This, then, is the code I used with a view to achieving this:

Dim ObjMail
Set ObjMail = Server.CreateObject("CDO.Message")
ObjMail.To = "sEmailAddress"
ObjMail.CC = "whoever@whatever.com"
ObjMail.BCC = "whoever@whatever.com"
ObjMail.From = sEmailAddress
ObjMail.Subject = "Your submission"
ObjMail.HTMLBody = <font face="verdana" color="navy" size="10pt">sFullNameTitle</font> & vbcrlf&_
sFullName & vbcrlf&_
<font face="verdana" color="navy" size="10pt">sEmailTitle</font> & vbcrlf&_
sEmailAddress & vbcrlf&_
<font face="verdana" color="navy" size="10pt">sBusinessTitle</font> & vbcrlf&_
sBusinessName & vbcrlf&_
<font face="verdana" color="navy" size="10pt">sCountryTitle</font> & vbcrlf&_
sCountryName & vbcrlf&_
MessageName & vbcrlf&_
<font face="verdana" color="navy" size="10pt">MessageTitle</font>
ObjMail.Send
Set ObjMail = Nothing
%>

This generates the following error:

Microsoft VBScript compilation error '800a03ea'

Syntax error

/welcome1.asp, line 70

ObjMail.HTMLBody = <font face="verdana" color="navy" size="10pt">sFullNameTitle</font> & vbcrlf&_
-------------------^

The error suggests that sFullNameTitle is wrong. Or is it my placement of the HTML code?

Many thanks to anyone with a helpful suggestion.

Steve
 
Where are all the quotes for the strings: <font fact=... etc?
 
as tsuji mentioned...you are missing a buttload of quotes...to include the leading one ..."<font face=


you may want to read up on "concatenation"

also...since you have repetition in your code you may want to consider subs/function/array/ for loop...google has plenty of examples...and, you may want to consider using styles vs html ...again...my demo will provide help....good luck


btw, it wasn't clear if you wanted a title AND a value ...so i added both...make sure to modify as needed...it's only a demo


code output:
Code:
<%
  sFullNameTitle  = "The Boss"
  sEmailNameTitle = "theboss@yahoo.com"
  sBusinessTitle  = "Big Bucks"
  sCountryTitle   = "U.S.A."
  sMessageTitle   = "You will need to replace these variable values w/ yours" & _
                    "...and don't forget to add to the arrays equally since" & _
                    " not using a 2D array"
  
  aTitles         = Array("Full Name","Email","Business","Country","Message")
  aTitleValues    = Array(sFullNameTitle,sEmailNameTitle,sBusinessTitle,sCountryTitle,sMessageTitle)

  For i = 0 to UBound(aTitles)
   sBodyHtml = sBodyHtml & " <tr>" & vbcrlf & _
                           "  <td valign=""top"" style=""width:20%;text-align:right;background:#eee;font-weight:bold;color:navy;border:1px solid black;"">" & aTitles(i) & ":</td>" & vbcrlf & _
                           "  <td style=""width:80%;border:1px solid black;"">" & aTitleValues(i) & "</td>" & vbcrlf & _
                           " </tr>" & vbcrlf
  Next

  sBodyHtml = "<table cellspacing=""0"" style=""width:600px;font-size:12px;font-family:verdana;border:1px solid black;"">" & vbcrlf & _
                sBodyHtml & _
              "</table>" & vbcrlf

  
  ' or do what you seem to be comfortable w/...but concatenating correctly

 sBodyHtml = "<font face=""verdana"" color=""navy"" size=""10pt"">" & sFullNameTitle & "</font><br>" & vbcrlf & _
             "<font face=""verdana"" color=""navy"" size=""10pt"">" & sEmailNameTitle & "</font><br>" & vbcrlf 

         '....


 
%>
 
Hello bslintx and tsuji

Thank you for your posts.
Yes, something like that on your brinkster site would be fine (maybe with out the borders).

Arrays are probably beyond me, so I have stuck to what I know (a bit of) and used the following:


Dim ObjMail
Set ObjMail = Server.CreateObject("CDO.Message")
ObjMail.To = "sEmailAddress"
ObjMail.CC = "whoever@whatever.com"
ObjMail.BCC = "whoever@whatever.com"
ObjMail.From = sEmailAddress
ObjMail.Subject = "Your submission"


sBodyHtml = "<font face=""verdana"" color=""navy"" size=""10pt"">" & sFullNameTitle & "</font><br>" & vbcrlf & _
"<font face=""verdana"" color=""navy"" size=""10pt"">" & sEmailNameTitle & "</font><br>" & vbcrlf
"<font face=""verdana"" color=""navy"" size=""10pt"">" & sBusinessTitle & "</font><br>" & vbcrlf
"<font face=""verdana"" color=""navy"" size=""10pt"">" & sCountryTitle & "</font><br>" & vbcrlf
"<font face=""verdana"" color=""navy"" size=""10pt"">" & sMessageTitle & "</font><br>" & vbcrlf

ObjMail.Send
Set ObjMail = Nothing
%>

Unfortunately, I am still getting an error message:

Expected statement

"<font face=""verdana"" color=""navy"" size=""10pt"">" & sBusinessTitle & "</font><br>" & vbcrlf
^

Is this to do with the 'concatenation' you mention?

Thanks again.

Steve


 
[tt][blue]
sBodyHtml = "<font face=""verdana"" color=""navy"" size=""10pt"">" & sFullNameTitle & "</font><br>" & vbcrlf & _
"<font face=""verdana"" color=""navy"" size=""10pt"">" & sEmailNameTitle & "</font><br>" & vbcrlf [!]& _[/!]
"<font face=""verdana"" color=""navy"" size=""10pt"">" & sBusinessTitle & "</font><br>" & vbcrlf [!]& _[/!]
"<font face=""verdana"" color=""navy"" size=""10pt"">" & sCountryTitle & "</font><br>" & vbcrlf [!]& _[/!]
"<font face=""verdana"" color=""navy"" size=""10pt"">" & sMessageTitle & "</font><br>" & vbcrlf
[/blue][/tt]

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Hello George

My mistake in not including the & _

The script does not generate an error message, and while the Webmaster receives an email entitled 'Your submission' as per this: ObjMail.Subject = "Your submission"

there is nothing else in the message. No Name, or Business, etc. No content at all.

Thanks, George, for your patience!

Steve


 
Well.... why didn't you say so. [smile] Just kidding.

I don't have a lot of experience with the CDO object but it seems to me as though you should be setting the 'body' property before actually sending the email.

Code:
Dim ObjMail 
Set ObjMail = Server.CreateObject("CDO.Message") 
ObjMail.To = "sEmailAddress" 
ObjMail.CC = "whoever@whatever.com"
ObjMail.BCC = "whoever@whatever.com"  
ObjMail.From = sEmailAddress 
ObjMail.Subject = "Your submission" 


sBodyHtml = "<font face=""verdana"" color=""navy"" size=""10pt"">" & sFullNameTitle & "</font><br>" & vbcrlf & _
"<font face=""verdana"" color=""navy"" size=""10pt"">" & sEmailNameTitle & "</font><br>" & vbcrlf & _
"<font face=""verdana"" color=""navy"" size=""10pt"">" & sBusinessTitle & "</font><br>" & vbcrlf   & _
"<font face=""verdana"" color=""navy"" size=""10pt"">" & sCountryTitle & "</font><br>" & vbcrlf  & _
"<font face=""verdana"" color=""navy"" size=""10pt"">" & sMessageTitle & "</font><br>" & vbcrlf 

[!]objMail.Body = sBodyHtml[/!]
ObjMail.Send 
Set ObjMail = Nothing  
%>

Like I said, I don't have a lot of experience with that object, so the correct property to use may not be body, but it's gotta be something, right?

I hope this helps.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Use single quotes in when useing asp and it should stop the error

<font face='verdana' color='navy' size='10pt'>sFullNameTitle</font>
 
Hello

Thank you both for replying.

I tried it with single quotes:

sBodyHtml = "<font face='verdana' color='navy' size='10pt'>" & sFullNameTitle & "</font><br>" & vbcrlf & _
"<font face='verdana' color='navy' size='10pt'>" & sEmailNameTitle & "</font><br>" & vbcrlf & _
"<font face='verdana' color='navy' size='10pt'>" & sBusinessTitle & "</font><br>" & vbcrlf & _
"<font face='verdana' color='navy' size='10pt'>" & sCountryTitle & "</font><br>" & vbcrlf & _
"<font face='verdana' color='navy' size='10pt'>" & sMessageTitle & "</font><br>" & vbcrlf

I do not get an error message, but like before, an empty email to the Webmaster (the site visitor who actually inputs the data (email address, etc) into the form fields does not get a copy.

When I insert this:

sBodyHtml = "<font face='verdana' color='navy' size='10pt'>" & sFullNameTitle & "</font><br>" & vbcrlf & _
"<font face='verdana' color='navy' size='10pt'>" & sEmailNameTitle & "</font><br>" & vbcrlf & _
"<font face='verdana' color='navy' size='10pt'>" & sBusinessTitle & "</font><br>" & vbcrlf & _
"<font face='verdana' color='navy' size='10pt'>" & sCountryTitle & "</font><br>" & vbcrlf & _
"<font face='verdana' color='navy' size='10pt'>" & sMessageTitle & "</font><br>" & vbcrlf

objMail.Body = sBodyHtml
ObjMail.Send
Set ObjMail = Nothing

that is, when I add the objMail.Body = sBodyHtml I get the folowing error:

Microsoft VBScript runtime error '800a01b6'

Object doesn't support this property or method: 'Body'

I feel as if we are getting there, but just not quite hitting the target!

Steve




 
Hello Sheco

Thanks for your post.

W3 suggests: myMail.HTMLBody so I have used:

objMail.HTMLBody = sBodyHtml
ObjMail.Send
Set ObjMail = Nothing

I do not get an error message, but no email is sent.

Can't understand it!

Steve
 
OK if you get to the point where there is no error then you can start to look at the configuration of the SMTP service and its interaction with the next upstream mail server.

If the mail server upstream is not accepting mail from your web server then your script will work but the mail won't go.

For example if you are on a windows network with Exchange as your mail server it may not accept any mail with a name in the FROM line that does not represent a valid email account in your active directory or it may have relays disabled as an antispam measure.

Is your web server on an intranet at your business or is it leased from a hosting provider? Sometimes you can get clues to these problems by poking around in the folders \Inetpub\mailroot\queue and \Inetpub\mailroot\badmail.

 
I know this code works with asp so I made you a copy for sample perpose but it should give you a place to start.


Set myMail=CreateObject("CDO.Message")

myMail.Subject="Your Subject"
myMail.From="account_processing@yourdomain.com"
myMail.To="support@yourdomain.com"
myMail.Bcc=session("yoursession")
myMail.TextBody="" & vbcrlf & vbcrlf & _
"Your Company. - YOUR COPY" & vbcrlf & vbcrlf & _
"----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----" & vbcrlf & _
"----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----" & vbcrlf & _
"PLEASE DO NOT REPLY TO THIS EMAIL!" & vbcrlf & _
"----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----" & vbcrlf & _
"----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----" & vbcrlf & vbcrlf & _

"Account ID: " & session("myvar16") & vbcrlf & _
"----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----" & vbcrlf & vbcrlf & _

"Person Authorizing: " & session("yoursession") & vbcrlf & _
"Position: " & session("yoursession") & vbcrlf & _
"Company: " & session("yoursession") & vbcrlf & _
"Type Of Business: " & session("yoursession") & vbcrlf & _
"Address: " & session("yoursession") & vbcrlf & _
"City: " & session("yoursession") & vbcrlf & _
"State: " & session("yoursession") & vbcrlf & _
"Zip + 4: " & session("yoursession") & "-" & session("myvar15") & vbcrlf & vbcrlf & _

"Phone: " & session("yoursession") & vbcrlf & _
"Fax: " & session("yoursession") & vbcrlf & _
"Email: " & session("yoursession") & vbcrlf & _
"Tax ID: " & session("yoursession") & vbcrlf & _
"Date: " & session("yoursession") & vbcrlf & vbcrlf & vbcrlf & _



"Terms Of Service Agreement" & vbcrlf & _
"-----" & vbcrlf & vbcrlf & _

"Test Here Sample" & vbcrlf & vbcrlf & _

"Yes, I " & session("yoursession") & ", agent for " & session("yoursession") & " agree to the above in its entirety." & vbcrlf & vbcrlf & _

"-->User Info: " & Request.ServerVariables("http_user_agent") & vbcrlf & _
"-->User Address: " & Request.ServerVariables("remote_addr")

myMail.Send
set myMail=nothing
 
Many thanks to all of you and to you Anon007

I have copied and pasted the script (from Anon007) and made a couple of changes.

I do not get an error message, but the Webmaster receives the following (only).

Fullname

Business
Country

There is no content in it (it ought to show the visitor's name, email address, business, etc), and the visitor does not get a copy in his/her inbox.

But it's a start!

Thank you.

Steve

 
Hello

This is what I have at the moment:

<%
Dim sFullNameTitle,sFullName,sEmailTitle,sEmailAddress,sBusinessTitle,sBusinessName,sCountryTitle,sCountryName,MessageName,MessageTitle
sFullNameTitle = "Fullname"
sFullName = Request.Form("Fullname")
sEmailTitle = "Email"
sEmailAddress = Request.Form("Email")
sBusinessTitle = "Business"
sBusinessName = Request.Form("Business")
sCountryTitle = "Country"
sCountryName = Request.Form("Country")
MessageName = "Message"
MessageTitle = Request.Form("Message")

Set myMail=CreateObject("CDO.Message")

myMail.Subject="Your Submission"
myMail.From="info@info.com"
myMail.To="sEmailAddress"
myMail.Cc="myAddress@yahoo.com"
myMail.Bcc="myOtherAddress@hotmail.com"

myMail.TextBody="Message" & vbcrlf & vbcrlf & _


"Your copy. Please do not reply to this email" & vbcrlf & _

"Full name: " & vbcrlf & _
"Email: " & vbcrlf & _
"Business: " & vbcrlf & _
"Country: " & vbcrlf & _
"Message: " & vbcrlf & _

myMail.Send
set myMail=nothing

%>

I am not getting any error messages, but neither does anyone receive any email messages.

Maybe I should be using myMail.HTMLBody = "<HTML Code here>" instead of:

myMail.TextBody="Message" & vbcrlf & vbcrlf & _

Yet, this does not explain why the data input in the form fields (or the email addresses) are not being picked up.

Any suggestions, please?

Thanks.

Steve
 
>myMail.To="sEmailAddress"
[tt]myMail.To=sEmailAddress[/tt]
Always have a clear mind on whether you type in a variable name or a literal string.
 
Code:
myMail.TextBody="Message" & vbcrlf & vbcrlf & _


"Your copy. Please do not reply to this email" & vbcrlf & _

"Full name:                         " & vbcrlf & _
"Email:                             " & vbcrlf & _
"Business:                          " & vbcrlf & _
"Country:                           " & vbcrlf & _
"Message:                           " & vbcrlf [!]& _[/!]

myMail.Send

The part highlighted in red should not be there. It's the line continuation operator, and there's nothing on the next line. [smile]

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Many thanks, again.

Slowly getting there!

I have got rid of the quotation marks and the message was received by the site visitor.

Then I removed the & _ and revisted the online form. This time the visitor did not receive a copy of their data via email (but that may be due to traffic).

The webmaster did receive a copy and it looks like this:

Message

Your copy. Please do not reply to this email
Full name:
Email:
Business:
Country:
Message:

So, the titles are appearing (as they are on the online form), but the content (name, country, etc), are not.

Cheers

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top