PDA

View Full Version : Simple Emailing Problem (CDONTS)


Icedan
09-06-2006, 06:31 AM
Ok I have a simple contact form, which you can see here:

http://www.orient-explorer.com/NEWOE/Contact.htm


I have done it this way because I don't want to publish the email addresses of each division.

On submission, it will pass through the following code:


<%
Dim YourName
Dim YourEmail
Dim Division
Dim Message
Dim Email2

YourName = Request.Form("YourName")
YourEmail = Request.Form("YourEmail")
Division = Request.Form("Division")
Message = Request.Form("Message")

if Division = MICE then
Email2 = "mail1@orient-explorer.com"
else if Division = Events then
Email2 = "mail2@orient-explorer.com"
else if Division = Conference then
Email2 = "mail3@orient-explorer.com"
else if Division = IT then
Email2 = "mail4@orient-explorer.com"
else if Division = Accounts then
Email2 = "mail5@orient-explorer.com"
else if Division = Ticketing then
Email2 = "mail6@orient-explorer.com"

end if
end if
end if
end if
end if
end if

MyBody = "<b>Details:</b>"
MyBody = MyBody & "<br><b>Name: </b>" & YourName
MyBody = MyBody & "<br><b>Email: </b>" & YourEmail
MyBody = MyBody & "<br><b>Division: </b>" & Division
MyBody = MyBody & "<br><b>Message: </b>" & Message

Set MyMail = Server.CreateObject ("CDONTS.NewMail")
MyMail.From = YourEmail
MyMail.To = Email2
MyMail.Bcc = "me@orient-explorer.com"
MyMail.Subject = "Mail from Orient Explorer Website"
MyMail.BodyFormat = 0
MyMail.MailFormat = 0
MyMail.Body = MyBody
MyMail.Send
set MyMail=nothing
%>


Note: I have changed the email addresses.

The code works, except it does not email to the respective person, it only emails to the Bcc.

I am aware that my problem area is within this code:

if Division = MICE then
Email2 = "mail1@orient-explorer.com"
else if Division = Events then
Email2 = "mail2@orient-explorer.com"
else if Division = Conference then
Email2 = "mail3@orient-explorer.com"
else if Division = IT then
Email2 = "mail4@orient-explorer.com"
else if Division = Accounts then
Email2 = "mail5@orient-explorer.com"
else if Division = Ticketing then
Email2 = "mail6@orient-explorer.com"

I had previously set the last line to "else Email2 = "mail6@orient-explorer.com", however, no matter what Division I selected in the menu, it would always email to mail6@orient-explorer.com

lovesirius12
09-06-2006, 10:24 AM
it's weird, but i dont see anything wrong

degsy
09-06-2006, 03:27 PM
I'm surprised you are not getting any errors showing.
The syntax is ElseIf, not Else If

and for than many selections you should use a Select Case statement instead.

Icedan
09-07-2006, 02:45 AM
no I know "else if" works, I use it many times.


If Programming was World of Warcraft, I would be a level 3, so could you please teach me what this Select Case Statement is about? I'm eager to learn as I have to create similar forms on a monthly basis :(

corics15
09-07-2006, 07:15 AM
Ok I have a simple contact form, which you can see here:

http://www.orient-explorer.com/NEWOE/Contact.htm


I have done it this way because I don't want to publish the email addresses of each division.

On submission, it will pass through the following code:


<%
Dim YourName
Dim YourEmail
Dim Division
Dim Message
Dim Email2

YourName = Request.Form("YourName")
YourEmail = Request.Form("YourEmail")
Division = Request.Form("Division")
Message = Request.Form("Message")

if Division = MICE then
Email2 = "mail1@orient-explorer.com"
else if Division = Events then
Email2 = "mail2@orient-explorer.com"
else if Division = Conference then
Email2 = "mail3@orient-explorer.com"
else if Division = IT then
Email2 = "mail4@orient-explorer.com"
else if Division = Accounts then
Email2 = "mail5@orient-explorer.com"
else if Division = Ticketing then
Email2 = "mail6@orient-explorer.com"

end if
end if
end if
end if
end if
end if

MyBody = "<b>Details:</b>"
MyBody = MyBody & "<br><b>Name: </b>" & YourName
MyBody = MyBody & "<br><b>Email: </b>" & YourEmail
MyBody = MyBody & "<br><b>Division: </b>" & Division
MyBody = MyBody & "<br><b>Message: </b>" & Message

Set MyMail = Server.CreateObject ("CDONTS.NewMail")
MyMail.From = YourEmail
MyMail.To = Email2
MyMail.Bcc = "me@orient-explorer.com"
MyMail.Subject = "Mail from Orient Explorer Website"
MyMail.BodyFormat = 0
MyMail.MailFormat = 0
MyMail.Body = MyBody
MyMail.Send
set MyMail=nothing
%>


Note: I have changed the email addresses.

The code works, except it does not email to the respective person, it only emails to the Bcc.

I am aware that my problem area is within this code:

if Division = MICE then
Email2 = "mail1@orient-explorer.com"
else if Division = Events then
Email2 = "mail2@orient-explorer.com"
else if Division = Conference then
Email2 = "mail3@orient-explorer.com"
else if Division = IT then
Email2 = "mail4@orient-explorer.com"
else if Division = Accounts then
Email2 = "mail5@orient-explorer.com"
else if Division = Ticketing then
Email2 = "mail6@orient-explorer.com"

I had previously set the last line to "else Email2 = "mail6@orient-explorer.com", however, no matter what Division I selected in the menu, it would always email to mail6@orient-explorer.com

try this:
select case Division
case MICE
Email2 = "mail1@orient-explorer.com"
case Events
Email2 = "mail2@orient-explorer.com"
case Conference
Email2 = "mail3@orient-explorer.com"
case IT
Email2 = "mail4@orient-explorer.com"
case Accounts
Email2 = "mail5@orient-explorer.com"
case Ticketing
Email2 = "mail6@orient-explorer.com"
end select

lemme know if it worked...:p

Icedan
09-07-2006, 11:55 AM
Tried it, sent to mail6@orient-explorer.com when it should have gone to mail3@orient-explorer.com

Is this a bug?

degsy
09-08-2006, 04:47 PM
In both the scripts posted the division is being compared to variables that don't exist.


if Division = MICE then



case MICE



You should be checking against strings.

angst
09-08-2006, 07:00 PM
also, incase no one else has mentioned this yet,
you should not be using CDONTS, use CDOSYS instead.
it's more secure, also CDONTS is not supported by windows server 2003, as such when you move your site or upgrade your server you'll have to redo your code.

Icedan
09-11-2006, 03:08 AM
angst, I am aware of CDOSYS, I would use it, but for some reason my hosters don't support it, which is really weird, as they tell me they are running Windows 2003.

degsy, what do you mean by checking against strings?

indiansoil
09-11-2006, 11:54 AM
Hi!


First of all I would like to say that your documentation is very neat. I found your Problem interesting. However, I am not an expert, yet I have found some errors in your codes which is the mere repetition of end if statement.

Try to use only one end if at the end of your codes:


if Division = MICE then
Email2 = "mail1@orient-explorer.com"
else if Division = Events then
Email2 = "mail2@orient-explorer.com"
else if Division = Conference then
Email2 = "mail3@orient-explorer.com"
else if Division = IT then
Email2 = "mail4@orient-explorer.com"
else if Division = Accounts then
Email2 = "mail5@orient-explorer.com"
else if Division = Ticketing then
Email2 = "mail6@orient-explorer.com"

end if
end if
end if
end if
end if
end if

There's no need of adding extra 'end if's because the complete block consists of one single "if... else if then ... end if" statment.

The 'end if's in red color are not required and are causing the erros!


Good luck to you!

Indiansoil

Icedan
09-11-2006, 12:00 PM
Thanks, I understand the method of end if's more clearly now, however it has not solved my problem. Interestingly though, it now emails to mail1@orient-explorer.com instead of mail6@orient-explorer.com (It should be going to mail3@orient-explorer.com as I selected "Conference" in the drop down menu on the contact page).

mehere
09-11-2006, 04:40 PM
you currently have this:
if Division = MICE then
Email2 = "mail1@orient-explorer.com"
else if Division = Events then
Email2 = "mail2@orient-explorer.com"
else if Division = Conference then
Email2 = "mail3@orient-explorer.com"
else if Division = IT then
Email2 = "mail4@orient-explorer.com"
else if Division = Accounts then
Email2 = "mail5@orient-explorer.com"
else if Division = Ticketing then
Email2 = "mail6@orient-explorer.com"

end if
end if
end if
end if
end if
end if
is MICE, Events, etc. variables are are they actual values? if they are values, you have to surround them with quotes. also, I would go with ElseIf to neaten up the code a bit.
if Division = "MICE" then
Email2 = "mail1@orient-explorer.com"
elseif Division = "Events" then
Email2 = "mail2@orient-explorer.com"
elseif Division = "Conference" then
Email2 = "mail3@orient-explorer.com"
elseif Division = "IT" then
Email2 = "mail4@orient-explorer.com"
elseif Division = "Accounts" then
Email2 = "mail5@orient-explorer.com"
elseif Division = "Ticketing" then
Email2 = "mail6@orient-explorer.com"
end if

Icedan
09-12-2006, 02:39 AM
Damn, I was going to try that, but something kept telling me not to.

Ok well I tried it and it didn't work. Same case as before.

I'm gonna switch to CDOSYS and hope that works.

Icedan
09-12-2006, 02:42 AM
Switching to CDOSYS does not work either.

Icedan
09-12-2006, 02:49 AM
Well I think I have exhausted my tries, so I guess you must have an email address value in the .To line.

While I am at it, I know a value would be something like "mail1@orient-explorer.com", does that mean a string is Email2? (according to my above code).

I just want to figure out what actually string is.

Icedan
09-12-2006, 03:32 AM
Ok figured it out.

Was a mistake on my end, one of my last attempts to get it working was to change the select menu to radio buttons; it didn't work, so I changed it back to the menu, however I had forgotten to name the menu, so mehere, your solution does work. Thanks.