Solved

code doesn't work

Posted on 2007-12-04
8
180 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

747 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

10 Experts available now in Live!

Get 1:1 Help Now