Link to home
Start Free TrialLog in
Avatar of Gemini532
Gemini532Flag for United States of America

asked on

code doesn't work

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
Avatar of b0lsc0tt
b0lsc0tt
Flag of United States of America image

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
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
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).
Avatar of Gemini532

ASKER

I got this from response.end

The email is [] and the type is Null
Does this help, if no one enters something if the email field it shows up as <NULL> in the database
ASKER CERTIFIED SOLUTION
Avatar of Göran Andersson
Göran Andersson
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
THANK YOU!