Solved

code doesn't work

Posted on 2007-12-04
8
183 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
 

Author Comment

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

The email is [] and the type is Null
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
CSS display:none AND display:block on same element 3 77
Import data into excel from web page 10 80
Animated .jpg? 13 59
Error in query expression 3 35
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now