Solved

code doesn't work

Posted on 2007-12-04
8
189 Views
Last Modified: 2010-04-21
Hello Everyone the code below does not work... can you help me figure out why?

if contactEmail = "" then
      contactEmail = "fake@fake.com"
end if
response.write contactEmail
response.End()
________________________________________________________________

Like for example if contactEmail  is blank, why does it not get replaced with the email I have as the default?!?!

________________________________________________________________

if contactEmail = "" then
      contactEmail = "fake@fake.com"
end if
response.write contactEmail
response.End()

'I get  blank, no email, even though logically it should give me the default email, how do I set a default email in this case?
________________________________________________________________


opicSubject = "Section IA."
opicBody = "body"

sendEmail emailBody, subject, recipient  'call function, send email if the data was submitted correctly


function sendEmail(body, subject, recepient)
            set objMail=Server.CreateObject("Jmail.SMTPMail")
                  objMail.ServerAddress = "00.00.00.00"
                  objMail.AddRecipient(recepient)      
                  objMail.Sender = "fake@fake.com"
                  objMail.Subject=subject                  
                  objMail.Body=body
                  objMail.Execute  
            end if             
            set objMail=nothing
end function




SO I GET THIS ERROR:

Microsoft VBScript runtime error '800a000d'

Type mismatch: 'objMail.AddRecipient'



because it cannot find an recepient
0
Comment
Question by:Gemini532
  • 3
  • 3
  • 2
8 Comments
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 20407081
Gemini532,

It looks like the problem is you aren't passing the variable to the function.  Try ...

sendEmail emailBody, subject, contactEmail  'call function, send email if the data was submitted correctly

Let me know if you have any questions or need more information.

b0lsc0tt
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 20407119
Gemini532,

Regarding the first part of the question the code looks good.  Most likely contactEmail is something else and not going in the If.  Try using ...

if contactEmail = "" then
      contactEmail = "fake@fake.com"
end if
response.write "The email is [" & contactEmail &"] and the type is " & Typename(contactEmail)
response.End()


Let me know if you have a question.

b0lsc0tt
0
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 20408087
If the email is "blank", and it's not an empty string, then it's likely Empty (null).

If IsEmpty(contactEmail) or contactEmail = "" Then
      contactEmail = "fake@fake.com"
End If

If you for example read a value from Request.QueryString, and no value was supplied in the url, the value that you get is not an empty string, it's the Empty value.

When you are calling the sendEmail function (which should actually be a Sub as it doesn't return any value), you don't use the variables that you have assigned on the previous lines. Have you assigned any values to the variables that you use?

Do you have Option Explicit in your code? If you don't, it will silently create new variables if you use variables that you haven't declared, or if you don't spell the variable names the same. I noticed that you used two different spellings for recipient/recepient (of which recipient is the correct spelling).
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

 

Author Comment

by:Gemini532
ID: 20441927
I got this from response.end

The email is [] and the type is Null
0
 

Author Comment

by:Gemini532
ID: 20442123
Does this help, if no one enters something if the email field it shows up as <NULL> in the database
0
 
LVL 29

Accepted Solution

by:
Göran Andersson earned 500 total points
ID: 20442625
Ok, then the value is Null, which is a special value that means that the value comes from a database field that was null, and it's not the same thing as Empty.

If IsNull(contactEmail) Then
      contactEmail = "fake@fake.com"
End If

Perhaps you also want to check if the value is an empty string (from an empty non-null database value):

If IsNull(contactEmail) or contactEmail = "" Then
      contactEmail = "fake@fake.com"
End If
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 20443326
Thanks for trying that and posting the results.  That is what we needed. :)

GreenGhost's last post should have the solution you need.  I'd recommend the second code so you still would test for an empty value.  You might also consider changing the database to not allow Null values in that field.  That might be more work right now or may not even be an option but could save you in the long run.  If you do allow Null values in a database then you need to remember that when writing the script that will check those values.

Let us know if you have a question about what has been said.  GreenGhost's last post should be exactly what you need though.  Thanks again for the results.

bol
0
 

Author Closing Comment

by:Gemini532
ID: 31412708
THANK YOU!
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Re-position the objects 7 117
Select case on click 3 19
alert(innerHTML); 8 32
Insert Button on a table 16 37
Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question