a webmaster learning community
     Home    Register     Search      Help      Login    
FrontPage Alternative
Sponsors

Hosting from $3.99 per month!

Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions. dd

Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

Search Forums
 

Advanced search
Recent Posts

 Todays Posts
 Most Active posts
 Posts since last visit
 My Recent Posts
 Mark posts read

 

email script question

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> ASP and Database >> email script question
Page: [1]
 
John316

 

Posts: 214
Joined: 9/25/2002
Status: offline

 
email script question - 5/8/2003 19:24:32   
All,

I have created a contact us web form for users to emailing me there problems. Here is my Question I have a field in my SQL Database called cities. Is there a way to setup a page so that if you are in a city it will email a certain person?

Example:

If you are from Dallas it will email - admin1@example.com

If you are from Houston it will email - admin2@example.com

I am including my email script below:

<%
Dim objNewMail

IF Request.Form(" cmdSend" ) = " Send" THEN
Set objNewMail = Server.CreateObject(" CDONTS.NewMail" )
objNewMail.From = Request.Form(" From" )
objNewMail.To = Request.Form(" To" )
objNewMail.Subject = Request.Form(" Subject" )
objNewMail.Body = Request.Form(" Message" )
objNewMail.Send
Set objNewMail = Nothing
Response.Redirect " Thankyou.asp"
END IF
%>


Thanks,
John316



< Message edited by john316 -- 5/8/2003 7:36 PM >
Jim McShane

 

Posts: 48
Joined: 8/13/2002
Status: offline

 
RE: email script question - 5/8/2003 21:23:10   
all you would have to do is use if then statement for each e-mail address based on the city entered in your submit form...

for example: on my jmail contact form i based the e-mail subject on a drop down box on my form... would imagine you could try something similar to this for CDONTS...

how many different email addresses do u have to send to... and are you manually coding the addresses or taking from a database??

' jmail sends mail to customer
Set JMail = Server.CreateObject(" JMail.SMTPMail" )
JMail.ServerAddress = " localhost"
JMail.Sender = Session(" vc_email_add" )
if Session(" v_category" ) = 1 then
JMail.Subject = " Medical Collection Boxes"
elseif Session(" v_category" ) = 2 then
JMail.Subject = " Miscellaneous Items"
elseif Session(" v_category" ) = 3 then
JMail.Subject = " Customization Options"
elseif Session(" v_category" ) = 4 then
JMail.Subject = " Suggestions or Comments"
elseif Session(" v_category" ) = 5 then
JMail.Subject = " Technical Issues"
end if

(in reply to John316)
rdouglass

 

Posts: 9280
From: Biddeford, ME USA
Status: offline

 
RE: email script question - 5/9/2003 10:12:05   
For long lists, a CASE statement may work better:

<%
Dim objNewMail, sendToVar

SELECT CASE myDBCityVariable

CASE " Dallas"
sendToVar = " bgates@microsoft.com"
Case " Houston
sendToVar = " sjobs@apple.com"
' .....
CASE ELSE
sendToVar = " me@myDomain.com"
END SELECT


IF Request.Form(" cmdSend" ) = " Send" THEN
Set objNewMail = Server.CreateObject(" CDONTS.NewMail" )
objNewMail.From = Request.Form(" From" )
objNewMail.To = sendToVar
objNewMail.Subject = Request.Form(" Subject" )
objNewMail.Body = Request.Form(" Message" )
objNewMail.Send
Set objNewMail = Nothing
Response.Redirect " Thankyou.asp"
END IF
%>

Generally speaking CASE works better for long lists IMO...hope it helps...:)

_____________________________

Don't take you're eye off your final destination.

ASP Checkbox Function Tutorial.

(in reply to John316)
John316

 

Posts: 214
Joined: 9/25/2002
Status: offline

 
RE: email script question - 5/9/2003 12:39:29   
The users email address are in my database and that field is called UserEmailAddress, the cities that the are are in are located in the column called city. I have 16 email address I want them to go to. Admin1@example.com to Admin16@example.com. I just want it so when the user submits a form and he is in Dallas it will send the email to Admin1@example.com and so on.

John316

(in reply to Jim McShane)
rdouglass

 

Posts: 9280
From: Biddeford, ME USA
Status: offline

 
RE: email script question - 5/9/2003 12:58:08   
Well, with only 16 addresses, I would tend to use a static list and the CASE statement like above. 16 seems to be a pretty manageable number to me.

How are you determining the city? Is it posted from the form? I know you stated that you have a field called " Cities" but how is that related to the problem? Can you just use Request as in:

SELECT CASE Request(" cities" )

???


_____________________________

Don't take you're eye off your final destination.

ASP Checkbox Function Tutorial.

(in reply to John316)
Jim McShane

 

Posts: 48
Joined: 8/13/2002
Status: offline

 
RE: email script question - 5/9/2003 13:14:29   
i agree with rdouglass...just use a drop down box on form with predetermined citys and then use the case statement to send to appropriate e-mail addresses...

-jim

(in reply to John316)
Jim McShane

 

Posts: 48
Joined: 8/13/2002
Status: offline

 
RE: email script question - 5/9/2003 13:21:38   
another question...

did you create this table in your database just to use for this form or is it part of your system. cause if your just making a this table for use on this form then i wouldn' t bother and use static list... but if u plan and using table dynamically then i would reconsider and maybe populate the drop down with the database and retrieve that certain e-mail address based on the drop down value.

-jim

(in reply to John316)
John316

 

Posts: 214
Joined: 9/25/2002
Status: offline

 
RE: email script question - 5/11/2003 22:22:19   
rdouglass,

The cities are predetermined based on the user registration. On our registration form it has them put what city they are in. So now I have created a contact us web form for users to emailing me there problems. I do have one question for you rdouglass on your response you tell me to

SELECT CASE myDBCityVariable

So here I would put my database name in? OR would it be the column they data is kept under?

Thanks for your help,
John316

(in reply to Jim McShane)
rdouglass

 

Posts: 9280
From: Biddeford, ME USA
Status: offline

 
RE: email script question - 5/12/2003 8:56:39   
quote:

So here I would put my database name in? OR would it be the column they data is kept under?


I know this probably won' t be a clear answer (:)) but it really does depend on where the data comes from. If this was ' inside' a DRW, you may use something like:

SELECT CASE FP_Field(fp_rs," myDBField" )

Or, if you use some other connection method, you may set the city as a Session or cookie during connection and use something like:

SELECT CASE Session(" myCity" )

Any help there?

By the way, are you using Spooky Login? If so, you could easily add a cookie to the login by editing " includes/a_general.asp" in the cookie section...:)

_____________________________

Don't take you're eye off your final destination.

ASP Checkbox Function Tutorial.

(in reply to John316)
John316

 

Posts: 214
Joined: 9/25/2002
Status: offline

 
RE: email script question - 5/12/2003 14:40:58   
I have used spooky login in the past but I am trying to learn some of this for myself. I do have a session. So you are saying I could do something like:

SELECT CASE Session(" cities" )


John316

(in reply to rdouglass)
rdouglass

 

Posts: 9280
From: Biddeford, ME USA
Status: offline

 
RE: email script question - 5/12/2003 15:37:20   
Sure could (if that is what you' re looking for of course...:))

Why make a DB call if you already have the info in a session variable??? Try it and see if it does what you' d expect...:)

_____________________________

Don't take you're eye off your final destination.

ASP Checkbox Function Tutorial.

(in reply to John316)
John316

 

Posts: 214
Joined: 9/25/2002
Status: offline

 
RE: email script question - 5/12/2003 17:29:09   
rdouglass,

It doesn' t work it skips all of your CASE statement and goes right to the else statemen:

CASE ELSE
sendToVar = " me@myDomain.com"


Any idea' s to why?
John316

(in reply to rdouglass)
rdouglass

 

Posts: 9280
From: Biddeford, ME USA
Status: offline

 
RE: email script question - 5/13/2003 9:22:23   
Do you have a valid session? IOW, can you do something like:

<%
Dim objNewMail, sendToVar

response.write Session(" cities" )

SELECT CASE Session(" cities" )

CASE " Dallas"
sendToVar = " bgates@microsoft.com"
Case " Houston
sendToVar = " sjobs@apple.com"
.....

Then check to see that the session is writeen to the screen. Without a valid session, you' ll always go to the CASE ELSE line.

Any help there?


_____________________________

Don't take you're eye off your final destination.

ASP Checkbox Function Tutorial.

(in reply to John316)
John316

 

Posts: 214
Joined: 9/25/2002
Status: offline

 
RE: email script question - 5/16/2003 3:21:45   
rdouglass,

How can I check to see if I hae a valid session?

John316

(in reply to rdouglass)
rdouglass

 

Posts: 9280
From: Biddeford, ME USA
Status: offline

 
RE: email script question - 5/16/2003 8:52:29   
<%=response.write Session(" cities" )%>

That should display what' s in the session " cities" . If nothing shows in the browser, you don' t have anything in the session (it doesn' t exist...)

_____________________________

Don't take you're eye off your final destination.

ASP Checkbox Function Tutorial.

(in reply to John316)
John316

 

Posts: 214
Joined: 9/25/2002
Status: offline

 
RE: email script question - 5/19/2003 20:21:03   
rdouglass,

When I add the code: <%=response.write Session(" cities" )%>

I see Dallas in the upper right hand corner. So I am not sure why it is going to the ELSE statement first? Do you have a clue?

John316

(in reply to rdouglass)
Spooky

 

Posts: 26617
Joined: 11/11/1998
From: Middle Earth
Status: online

 
RE: email script question - 5/20/2003 4:57:26   
Also, check the case of the text.
Ensure all of the case statements use lower case like below :


SELECT CASE lCase(Session(" cities" ))
CASE " dallas"  


_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

§þ:)


(in reply to John316)
Cookie

 

Posts: 297
Joined: 2/7/2002
From: UK
Status: offline

 
RE: email script question - 5/20/2003 5:11:00   
Surely a simpler solution would be to to have the dropdown with all the cities and the value it submits would be the email address it needs to go to.

Then....

on the email form you just request that value.

Dave

(in reply to John316)
John316

 

Posts: 214
Joined: 9/25/2002
Status: offline

 
RE: email script question - 5/23/2003 17:19:24   
Spooky & Cookie,

I did a response.write Session(" cities" ) and it looks like the case statement is working. How do I get the email address to show up in a text box?
This is what I have and I know it is not right, not sure what the value should be in a Case Statement:

<tr>
<td valign=" top" align=" left" ><b>To Address:</b></td>
<td valign=" top" align=" left" >
<input type=" text" name=" To" size=" 65" tabindex=" 2" value=" sendToVar" >
</td>


Thanks,
John316

(in reply to Spooky)
Spooky

 

Posts: 26617
Joined: 11/11/1998
From: Middle Earth
Status: online

 
RE: email script question - 5/23/2003 17:37:36   
What does the script look like for the case?

_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

§þ:)


(in reply to John316)
John316

 

Posts: 214
Joined: 9/25/2002
Status: offline

 
RE: email script question - 5/25/2003 17:02:21   
at the top of the page and the form is at the bottom of the page

John316

(in reply to Spooky)
Spooky

 

Posts: 26617
Joined: 11/11/1998
From: Middle Earth
Status: online

 
RE: email script question - 5/26/2003 16:51:15   
.....value=" <%=sendToVar%>" >

_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

§þ:)


(in reply to John316)
John316

 

Posts: 214
Joined: 9/25/2002
Status: offline

 
RE: email script question - 5/27/2003 11:28:37   
Thanks Spooky it worked


John316

(in reply to Spooky)
Page:   [1]
OutFront Discoveries

All Forums >> Web Development >> ASP and Database >> email script question
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts