PDA

View Full Version : logic error on CDONTS email object??


charon
11-21-2002, 02:44 AM
hi,

I wonder why once I call two Subroutine, the mail object failed to send the email, for instance:
AutoRespond place, fphone, emailTo, sender, subject
AutoNotify emailCopy, uName, place, Notes, sender, subject

if I call only one subroutine (AutoRespond/AutoNotify), it be able to function properly. May I know why???

below is my mail subroutine:

<%

SUB sendMail( fromWho, toWho, Body, Rcheck, subject )
Dim myMail
'Body = Replace(Body, VBCrLf, "<br>")
Body = Replace(Body,Chr(13),"<br>")
SET myMail = Server.CreateObject("CDONTS.NewMail")
myMail.MailFormat = 0
myMail.BodyFormat = 0
myMail.To = toWho
myMail.From = fromWho
'myMail.Bcc = toWho
myMail.Subject = subject
myMail.Body = Body

If Rcheck <> "" Then
myMail.Cc = fromWho
End If

myMail.Send
SET myMail = Nothing

If Redirect <> "" Then
Response.Redirect Redirect
Else
Response.Write "Your mail has been sent."
End If

END SUB

Sub AutoRespond(place, tel, mailto, sender, subject)
Dim Rcheck

msg = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & vbCrLf & _
"Setiahomes.com - Discover The Natural Place to Call Home" & vbCrLf & _
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & vbCrLf & vbCrLf & _
"Dear Sir/Madam," & vbCrLf & vbCrLf & _
"Thank you for registering at www.setiahomes.com" & vbCrLf & vbCrLf & _
"We are pleased to confirm that your registration for future launches in " & _
place & " has been received." & vbCrLf & vbCrLf & _
"We will keep you informed of the latest developments and invite you to " & _
"the sales launch for the phases you are interested in as the launch " & _
"dates draw nearer." & vbCrLf & vbCrLf & _
"To speak to our sales and marketing representatives, call us at " & _
tel & vbCrLf & vbCrLf & _
"Our offices are open Monday to Friday from 9.00 a.m. to 5.15 p.m. and " & _
"Saturdays from 9.00 a.m. to 4.00 p.m. We are closed on the first " & _
"Saturday of every month." & vbCrLf & vbCrLf & _
"Thank you." & vbCrLf & vbCrLf & _
"The Management of S P Setia Bhd" & vbCrLf & vbCrLf & _
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & vbCrLf & _
"Setiahomes.com - Discover The Natural Place to Call Home" & vbCrLf & _
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"

If mailto <> "" Then
sendMail sender, mailto, msg, Rcheck, subject
End If


End Sub

Sub AutoNotify(emailcopy, registrant, place, comment, sender, subject)
Dim Rcheck

msg = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & vbCrLf & _
"Setiahomes.com - Discover The Natural Place to Call Home" & vbCrLf & _
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & vbCrLf & vbCrLf & _
"Dear Our Sales Person," & vbCrLf & _
"This is an email to notify you that " & registrant & vbCrLf & _
"has been registered for the " & place & " futurelauches. " & vbCrLf & _
"Below is " & registrant & " extra notes: " & vbCrLf & Comment & vbCrLf & _
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & vbCrLf & _
"Setiahomes.com - Discover The Natural Place to Call Home" & vbCrLf & _
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"

If emailcopy <> "" Then
sendMail sender, emailcopy, msg, Rcheck, subject
End If


End Sub

%>

Please help!!!!!

glenngv
11-21-2002, 03:12 AM
can you post the part of the code where you call those subroutines? and is there any error message?

charon
11-21-2002, 03:30 AM
I'm sure there has nothing wrong with another aprt of the coding as It is just like what I have posted:

AutoRespond place, fphone, emailTo, sender, subject
AutoNotify emailCopy, uName, place, Notes, sender, subject

All the variable is passed correctly. The miracle only happen when these two functions call at the same time (one after another). If I disable either one, it works great.

I did try to write a simple code whereby I call two functions, it failed to work, only the first function manage to send the mail.

May be you can try yourself by code two simple functions and call them as what I did. If it works fine, then that mean there has nothing wrong with the CDONTS mail object, but my coding.


Thanks so much if you can help!

glenngv
11-21-2002, 05:21 AM
don't know if this would be of any help, but try putting ByVal in each of the subroutine parameter

SUB sendMail(ByVal fromWho, ByVal toWho, ByVal Body, ByVal Rcheck, ByVal subject )
END SUB

Sub AutoRespond(ByVal place, ByVal tel, ByVal mailto, ByVal sender, ByVal subject)
End Sub

Sub AutoNotify(ByVal emailcopy, ByVal registrant, ByVal place, ByVal comment, ByVal sender, ByVal subject)
End Sub

charon
11-23-2002, 01:31 AM
thanks so much whammy ,

I thought no body be able to solve the problem, i'm so luckly to get your reply, but I'm not really understand what do you mean by "Instead, create (and close it, set it to nothing) inside each subroutine, and it should work just fine. "

Hope that i'm not misunderstanding, below is my code.


<%

Sub AutoRespond(place, tel, mailto, sender, subject)
Dim Rcheck

msg = " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~" & vbCrLf & _
"Setiahomes.com - Discover The Natural Place to Call Home" & vbCrLf & _
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~" & vbCrLf & vbCrLf & _
"Dear Sir/Madam," & vbCrLf & vbCrLf & _
"Thank you for registering at www.setiahomes.com" & vbCrLf & vbCrLf & _
"We are pleased to confirm that your registration for future launches in " & _
place & " has been received." & vbCrLf & vbCrLf & _
"We will keep you informed of the latest developments and invite you to " & _
"the sales launch for the phases you are interested in as the launch " & _
"dates draw nearer." & vbCrLf & vbCrLf & _
"To speak to our sales and marketing representatives, call us at " & _
tel & vbCrLf & vbCrLf & _
"Our offices are open Monday to Friday from 9.00 a.m. to 5.15 p.m. and " & _
"Saturdays from 9.00 a.m. to 4.00 p.m. We are closed on the first " & _
"Saturday of every month." & vbCrLf & vbCrLf & _
"Thank you." & vbCrLf & vbCrLf & _
"The Management of S P Setia Bhd" & vbCrLf & vbCrLf & _
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~" & vbCrLf & _
"Setiahomes.com - Discover The Natural Place to Call Home" & vbCrLf & _
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~"

If mailto <> "" Then
Dim myMail
'Body = Replace(Body, VBCrLf, "<br>")
Body = Replace(Body,Chr(13),"<br>")
SET myMail = Server.CreateObject("CDONTS.NewMail")
myMail.MailFormat = 0
myMail.BodyFormat = 0
myMail.To = mailto
myMail.From = sender
'myMail.Bcc = mailto
myMail.Subject = subject
myMail.Body = Body

If Rcheck <> "" Then
myMail.Cc = sender
End If

myMail.Send
SET myMail = Nothing

If Redirect <> "" Then
Response.Redirect Redirect
Else
Response.Write "Your mail has been sent."
End If

End If


End Sub

Sub AutoNotify(emailcopy, registrant, place, comment, sender, subject)
Dim Rcheck

msg = " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~" & vbCrLf & _
"Setiahomes.com - Discover The Natural Place to Call Home" & vbCrLf & _
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~" & vbCrLf & vbCrLf & _
"Dear Our Sales Person," & vbCrLf & _
"This is an email to notify you that " & registrant & vbCrLf & _
"has been registered for the " & place & " futurelauches. " & vbCrLf & _
"Below is " & registrant & " extra notes: " & vbCrLf & Comment & vbCrLf & _
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~" & vbCrLf & _
"Setiahomes.com - Discover The Natural Place to Call Home" & vbCrLf & _
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~"

If emailcopy <> "" Then
Dim myMail
'Body = Replace(Body, VBCrLf, "<br>")
Body = Replace(Body,Chr(13),"<br>")
SET myMail = Server.CreateObject("CDONTS.NewMail")
myMail.MailFormat = 0
myMail.BodyFormat = 0
myMail.To = emailcopy
myMail.From = sender
'myMail.Bcc = toWho
myMail.Subject = subject
myMail.Body = Body

If Rcheck <> "" Then
myMail.Cc = sender
End If

myMail.Send
SET myMail = Nothing

If Redirect <> "" Then
Response.Redirect Redirect
Else
Response.Write "Your mail has been sent."
End If

End If


End Sub

%>

But, I'm wondering, why the mail instance must create inside the subroutine????? Why it works fine if only one function is called. HOpe you be able to answer me these two questions or is there any article which I can fefer?

charon
11-23-2002, 02:34 AM
hi, whammy,

I hope that you won't et frustrated with my questions. I'm just wondering, doesn't the mail object has already set to nothing from the first sub subroutine.


Sub SendSomeMail()
Set mynewmail = Server.CreateObject("CDONTS.NewMail")
'more stuff here
Set mynewmail = Nothing
End Sub

Sub SendSomeMOREMail()
Set mynewmail = Server.CreateObject("CDONTS.NewMail")
'send another email
Set mynewemail = Nothing
End Sub

-------------------------------------------------------------------------------

So, base on my original sendmail subroutine:

SUB sendMail( fromWho, toWho, Body, Rcheck, subject )
Dim myMail
'Body = Replace(Body, VBCrLf, "<br>")
Body = Replace(Body,Chr(13),"<br>")
SET myMail = Server.CreateObject("CDONTS.NewMail")
myMail.MailFormat = 0
myMail.BodyFormat = 0
myMail.To = toWho
myMail.From = fromWho
'myMail.Bcc = toWho
myMail.Subject = subject
myMail.Body = Body

If Rcheck <> "" Then
myMail.Cc = fromWho
End If

myMail.Send
SET myMail = Nothing

If Redirect <> "" Then
Response.Redirect Redirect
Else
Response.Write "Your mail has been sent."
End If

END SUB


AutoResponse var1, var2, var3, var4
AutoNotify var1, var2, var3, var 4

After the AutoResponse is called, the newmail object has already set to nothing, that mean has alreasy release.

Once the AutoNotify is called, it generates the newmail instance again, so where got wrong.

Do hope I'm not out of track.

Thanks so much for your patient.

whammy
11-23-2002, 04:18 AM
Ahh. I see now, you use that a bit differently than I would - and I didn't see that you were passing those variables to your subroutine (I would always use a function for something like that, just habit).

Hmm, for starters I would make sure all of the required variables are receiving a value in your subroutine, using response.write()...

charon
11-23-2002, 04:28 AM
hi whammy,

I'm not really catch what do you mean....
but, don't wory, I passed all the argument correctly..

AutoResponse var1, var2, var3, var4, var
AutoNotify var1, var2, var3, var 4, var

I just make typo mistake when post the forum.

Problem seems like not yet solved.

OK, let me explain again. Base on my first forum which I posted, there are three subroutine:
1) sendMail
2.)AutoResponse
3.)AutoNotify


And I'm here would like to emphasize again that

After the AutoResponse is called, the newmail object has already set to nothing, that mean has already released

Once the AutoNotify is called, it generates the newmail instance again, so where got wrong????






:confused: :(

whammy
11-24-2002, 12:39 AM
Hmm... my best suggestion would be to comment out the call to the actual .send in your SendMail() Sub, and response write the variables you are passing to it to make sure they aren't losing their value somewhere.

After looking at this again, I realized I was wrong (unless for some reason you should be using a function instead of subs, I'm not sure because I always use functions when I pass values).

If nothing else works, try that...