Help with asp website form

M

Mike

I'm used to unix/cgi scripts so im slightly out of my depth here.
Ive got an asp script for a website form which works fine.
What i want to do is also get the form to include the ip address of the
perosn sending the form ie
<input type=hidden name=env_report value=REMOTE_ADDR>
Anyone know how to apply this to this asp script below?:



<%
For Each x in request.form
sBody = sBody & x & " = " & request.form(x) & vbCrLf
Next
Set MailObject = Server.CreateObject("CDONTS.NewMail")
MailObject.From = "(e-mail address removed)"
MailObject.To = "(e-mail address removed)"
MailObject.Subject = "Form"
MailObject.Body = sBody & vbCrLf

MailObject.Send
Set MailObject = Nothing
' Now redirect
Response.Redirect "http://www.xxx/thank_you.htm"
%>
 
C

Curt_C [MVP]

you mean you want to get the literal "REMOTE_ADDR" as the from?

Request.Form("inputNameHere")
will get you what you want, it retrieves the value
 
M

Mike

Curt_C said:
you mean you want to get the literal "REMOTE_ADDR" as the from?

Request.Form("inputNameHere")
will get you what you want, it retrieves the value

tried that but without success. i'm not quite sure where to insert this.
Can you edit my code below so i can see exactly what/where you mean
 
R

Ray at

Try:


<%
For Each x in request.form
sBody = sBody & x & " = " & request.form(x) & vbCrLf
Next

sBody = sBody & "IP Address: " & Request.ServerVariables("REMOTE_ADDR")
''rest of your code


Also, instead of CDONTS, you should be using CDO, unless you're on an NT 4
server. CDONTS is being phased out.
http://www.aspfaq.com/show.asp?id=2026

Ray at home
 
J

Jeff Cochran

Also, keep in mind that the reported IP may or may not be the actual
IP, since proxies and NAT can report a different IP.

Jeff
 
R

Ray at

Not to mention that by grabbing the value from a form element, it can be
whatever value someone wants it to be then, like if someone created his own
form and posted it. I don't know anyone would want to do that in this
particular example though.

Ray at home
 
M

Mike

Ray at said:
Try:


<%
For Each x in request.form
sBody = sBody & x & " = " & request.form(x) & vbCrLf
Next

sBody = sBody & "IP Address: " & Request.ServerVariables("REMOTE_ADDR")
''rest of your code


Also, instead of CDONTS, you should be using CDO, unless you're on an NT 4
server. CDONTS is being phased out.
http://www.aspfaq.com/show.asp?id=2026

Ray at home


Thanks ray that works a treat, just the help i was after. Thanks for that
:)
 
M

Mike

Also, instead of CDONTS, you should be using CDO, unless you're on an NT 4
server. CDONTS is being phased out.
http://www.aspfaq.com/show.asp?id=2026

Ray at home


Is this likely to be phased out soon?
FYI: The host is www.hostmysite.com

As i said i know nothing about asp / CDONTS / CDO.

currently i am using the above script with a form action of:

<form name="form" method="post" action="http://www.xxx.com/form.asp">

Is there a simple way to alter the current script to CDO or am i going to
have to look for somehting new?

Your advice is appreciated
 
C

Curt_C [MVP]

Win2000 is the last server OS to carry CDONTS natively, and already has CDO
as well.
Win2003 is CDO
 
R

Ray at

Changing from CDONTS to CDO isn't really hard. You could probably actually
do it with a find/replace in a text editor, for the most part. But
something else to consider is to create a sub or a function to handle
e-mailing and use that in your code, so that if you have to change mail
components, you just change the code in your sub.


Sub SendAnEmail(sFrom, sTo, sSubject, sBody)
Set oMail = CreateObject("YourMailComponent")
'''code to send e-mail

End Sub


Then anywhere in your ASP code where you need to send e-mail, just call the
sub and pass the arguments. You'd want to put this sub in an include file
so you can use it in any page.

Ray at home
 
M

Mike

Ray at said:
Changing from CDONTS to CDO isn't really hard. You could probably actually
do it with a find/replace in a text editor, for the most part. But
something else to consider is to create a sub or a function to handle
e-mailing and use that in your code, so that if you have to change mail
components, you just change the code in your sub.


Sub SendAnEmail(sFrom, sTo, sSubject, sBody)
Set oMail = CreateObject("YourMailComponent")
'''code to send e-mail

End Sub


Then anywhere in your ASP code where you need to send e-mail, just call the
sub and pass the arguments. You'd want to put this sub in an include file
so you can use it in any page.

Ray at home


not sure im with you on the changes.

Does anyone have a basic default cdo asp file script knocking about that
simply sends the form contents
and provides a redirect page.

Im simply looking for an asp which can be called via:

<form name="form" method="post" action="http://www.xxx.com/form.asp">

whch then submits to email. i think it would be wise if i find a CDO one
now rather than later.

cgi/unix scripts are 10 a penny but asp ones seem more difficult to find
 
R

Ray at

not sure im with you on the changes.

That's okay. One step at a time.


Does anyone have a basic default cdo asp file script knocking about that
simply sends the form contents
and provides a redirect page.

I posted a decent link in my first reply yesterday. Did you check out the
page? Here's the link again.
http://www.aspfaq.com/show.asp?id=2026


i think it would be wise if i find a CDO one
now rather than later.

I commend you for that attitude. Most people would say the Hell with it and
make things harder for themselves later on. Good job. :]

cgi/unix scripts are 10 a penny but asp ones seem more difficult to find

If you have not already done so, bookmark http://www.darkfalz.com/ and the
the sites found at http://www.darkfalz.com/Links.aspx.

Ray at work
 
M

Mike

Ok this basic cdo script seems to dot he trick.

<%@ Language=VBScript %>
<%
Option Explicit
Dim iMsg
Set iMsg = CreateObject("CDO.Message")
iMsg.To = "(e-mail address removed)"
iMsg.Subject = "This is the Subject"
iMsg.From = "Me <[email protected]>"
iMsg.TextBody = "This is the body of the message"
iMsg.Send
%>
The problem is how i go about adding the following elements:

1) Getting the form to submit the contents of all form fields.
Obviously currently all it submits is the text body message: "This is the
body of the message"

2) Specifying a redirect url
Response.Redirect "http://www.xxx.com/thank_you.htm"

3) Adding the ip address of the form sender ie:
sBody = sBody & "IP Address: " & Request.ServerVariables("REMOTE_ADDR")


Any help in correctly adding the above to the script would be appreciated
 
R

Ray at

Mike said:
Ok this basic cdo script seems to dot he trick.

<%@ Language=VBScript %>
<%
Option Explicit
Dim iMsg
Set iMsg = CreateObject("CDO.Message")
iMsg.To = "(e-mail address removed)"
iMsg.Subject = "This is the Subject"
iMsg.From = "Me <[email protected]>"
iMsg.TextBody = "This is the body of the message"
iMsg.Send
%>
The problem is how i go about adding the following elements:

1) Getting the form to submit the contents of all form fields.
Obviously currently all it submits is the text body message: "This is the
body of the message"

Remember in your original post you had that For Each x in request.form
line...? You can still use that variable in place of the text string that's
currently set as the .textbody.
2) Specifying a redirect url
Response.Redirect "http://www.xxx.com/thank_you.htm"

Use that exact line that you have there. (Or just response.redirect
"/thankyou.htm" if this is all taking place on your site.)
3) Adding the ip address of the form sender ie:
sBody = sBody & "IP Address: " & Request.ServerVariables("REMOTE_ADDR")

As covered in the original reply. I think now it's just a matter of piecing
it all together.

Ray at work
 
M

Mike

Ray at said:
Remember in your original post you had that For Each x in request.form
line...? You can still use that variable in place of the text string that's
currently set as the .textbody.


Use that exact line that you have there. (Or just response.redirect
"/thankyou.htm" if this is all taking place on your site.)


As covered in the original reply. I think now it's just a matter of piecing
it all together.

Ray at work


Hi
sry not sure i was clear, i tried to create the right script but because
i'm not familar with asp i can't find the errors.
perhaps easier if i post what i have (see below). can you tell me whats
wrong?


<%@ Language=VBScript %>
<%
Option Explicit
Dim iMsg
Set iMsg = CreateObject("CDO.Message")
For Each x in request.form
sBody = sBody & x & " = " & request.form(x) & vbCrLf

iMsg.To = (e-mail address removed)
iMsg.Subject = "This is the Subject"
iMsg.From = "Me (e-mail address removed)"
iMsg.Body = sBody & vbCrLf
iMsg.sBody = sBody & "IP Address: " &
Request.ServerVariables("REMOTE_ADDR")

iMsg.Send
Response.Redirect "/thank_you.htm"
%>
 
R

Ray at

You didn't close your For loop.

<%@ Language=VBScript %>
<%
Option Explicit
Dim iMsg
For Each x in request.form
sBody = sBody & x & " = " & request.form(x) & vbCrLf
Next


Set iMsg = CreateObject("CDO.Message")
iMsg.To = (e-mail address removed)
iMsg.Subject = "This is the Subject"
iMsg.From = "Me (e-mail address removed)"
iMsg.Body = sBody & vbCrLf
iMsg.sBody = sBody & "IP Address: " &
Request.ServerVariables("REMOTE_ADDR")

iMsg.Send
Response.Redirect "/thank_you.htm"
%>

Ray at work
 
R

Ray at

I did not look closely enough. There's no .body or .sbody thing. You had
the right property in there before. .TextBody.

Ray at work
 
M

Mike

I must be close! grrr.
Any pointers what is wrong?


<%@ Language=VBScript %>
<%
Option Explicit
Dim iMsg
For Each x in request.form
sBody = sBody & x & " = " & request.form(x) & vbCrLf
Next

Set iMsg = CreateObject("CDO.Message")
iMsg.To = (e-mail address removed)
iMsg.Subject = "This is the Subject"
iMsg.From = "Me (e-mail address removed)"
iMsg.TextBody = "This is the body of the message"
Request.ServerVariables("REMOTE_ADDR")

iMsg.Send
Response.Redirect "/thank_you.htm"
%>
 
R

Ray at

I really think that if you step back and look at everything, you'll be able
to piece it all together. I don't mean this in a snide way, but is your
intention to learn ASP or just get this script working and not care about
learning anything?

Ray at work
 
M

Mike

Ray at said:
I really think that if you step back and look at everything, you'll be able
to piece it all together. I don't mean this in a snide way, but is your
intention to learn ASP or just get this script working and not care about
learning anything?

Ray at work

The best way i learn this basic stuff is by knowing the answer (ie seeing a
working script) so I can see
where its wrong and work backwards.
I appreciate what your saying, youve helped enough.

Can anyone else tell me what is wrong with this basic script?

many thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top