Form to email ASP script

admin

Administrator
Staff member
Hi All,

Does anyone have a (fairly simple) ASP "form to email" script that they could share ?

I have a simple 2 field form requesting email address and name that I would like to have emailed to me after completion.

All help very much appreciated.as always, check <!-- w --><a class="postlink" href="http://www.hotscripts.com">www.hotscripts.com</a><!-- w --> first.

if a pre-made script is your quest, then that is the place to start.Thanks for that Putts,

So I now have a form and an ASP script.......and a new problem

I customised the script to suit my environment, and uploaded the script to my server, but
when I now complete the form and hit "Submit" it actually tries to load the script as a web page.

Here's the form :-

<form action="http://www.mywebsite.co.uk/files/formtomail.asp" method="post" name="enews.form" target="_self" class="style15" id="enews.form">
<p><span class="style1">Email Address:</span>
<input name="youremail" type="text" class="style1" id="youremail">
</p>
<p><span class="style1">Name:</span>
<input name="yourname" type="text" class="style1" id="yourname">
</p>
<p class="style1"> <input type="submit" value="Submit"> </p>
</form>


And here's the ASP script :-

<%
For Each x In Request.Form
message = message & x & ": " & Request.Form(x) & CHR(10)
Next
set smtp=Server.CreateObject("Bamboo.SMTP")
smtp.Server="mail.mywebsite.co.uk"
smtp.Rcpt="[email protected]"
smtp.From="enews.form("youremail")"
smtp.FromName="enews.form("yourname")"
smtp.Subject="Response from website - eNews"
smtp.Message = message
on error resume next
smtp.Send
if err then
response.Write err.Description
else
Response.redirect ("http://www.mywebsite.co.uk/thanks.htm")
end if
set smtp = Nothing
%>


I must be missing something pretty basic here........any help very much appreciated.Do you have any other ASP pages on the same server that are running ok?Hi Goldilocks,

Not at the moment. This is a new server to me.Are you sure that it supports ASP, or that it is enabled? It sounds like some kind of server setup problem, I didn't see anything immediately wrong with your code, but then I'm no expert.

Where is your site hosted? Is it with another company or do you have your own server?The site is not yet launched, I'm still developing it so all my testing is local. Although I have uploaded th ASP script to the servers that I will use.

I'll check with the hosting company to make sure their are no problems with ASP.

Thanks again for your advice.Well the server owners say their are no problems with ASP scripts on their servers...

But when I submit the form it still tries to open the script as a window rather than
processing the form contents with it.Hmm. When you view the page, what do you type in the address bar? Is it the full website address etc? It would be useful to see it for ourselves, or do you not want to give out the address just yet?

If the problem was an error in your code then you would expect to see an asp error but it's like the code isn't running at all. All i can suggest is that you try creating a very simple asp page and uploading that to see if it runs at all. That would rule out a coding problem anyway. Something like this:


<%@ Language=VBScript %>
<html>
<head>
<title>ASP Test</Title>
</head>

<body>

<%
response.write("Hello world")
%>

</body>

</html>


I know I am really stating the obvious here but you did save the file with the asp script as a .asp and not a .html didn't you? Sorry if that sounds really patronizing, I don't know how well you know ASP that's all! I'm just trying to think of every little possibility!It sounds to me like it's doing exactly what it should be doing. When you submit a form, it goes to whatever page is declared in the action attribute. If that page has scripting in it, it'll run the scripting, but it still goes to that page. What's usually done is that, after the ASP scripting, you add in the HTML to make a short page that will be displayed to the client. Something like:<%
'ASP scripting goes here
%>
<html>
<head>
<title>Thank you</title>
</head>
<body>
<p>Thank you for submitting your email.</p>
</body>
</html>If you don't want it to load a new page, include the ASP in form page, and have it test for form submission before it runs, then set the action of the form to the same page.

RysWell from what I understand, he is getting the actual ASP code appearing in the browser window (like on the image I have attached). This happens when the ASP code isn't being executed on the server before returning HTML to the browser. It's almost reading it like a text file.The site is still in very early stages of being built so I only have it on
my local PC at the moment.

The scenario is..........

The .asp script is on a temporary server that supports .asp (This is for testing purposes).

When I go to the index page and complete the form, I hit submit, it looks as if the window is trying to open the file rather than post the form info to it.

e.g. I get, in a new window, HTTP 500 - Internal server error - The page cannot be displayedremove friendly error messages .... Tools -> Options ->Advanced ->Uncheck show friendly errors.

Then try it.... as it will give you more complete details of teh nature of the error.In that case, the only idea I have -- and I can't claim it's a good one -- is that the problem may be caused by trying to run the file off a local machine. Since it's not being accessed over HTTP (unless you've got a server running on your local machine), it can't run the ASP properly. Try copying the form up to the server and accessing it as a normal web page, rather than locally.

Ryshmmmmmmm it would not return 500 error. that is a server error. i beleive you need to re-read his post. he says he has a local server. and it will be moving to a production server.Thats correct. The script is actually on a remote server.

I've just tried uploading the form page to the remote server also, and I still get the same problem.

I've unchecked friendly errors and this is now what I get :-

Microsoft VBScript compilation error '800a0400'

Expected statement

/ebiz2005/files/formtomail.asp, line 3

\line For Each x In Request.Form \line message = message & x & ": " & Request.Form(x) & CHR(10) \line Next \line set smtp=Server.CreateObject("Bamboo.SMTP") \line smtp.Server="\cf1 mail.ebizsolutions.co.uk\cf0 " \line smtp.Rcpt="\cf1 <!-- e --><a href="mailto:[email protected]">[email protected]</a><!-- e -->\cf0 " \line smtp.From="\cf1 enews.form("youremail")\cf0 " \line smtp.FromName="\cf1 enews.form("yourname")\cf0 " \line smtp.Subject="\cf1 Response from ebizsolutions - Contact Us\cf0 " \line smtp.Message = message \line on error resume next \line smtp.Send \line if err then \line response.Write err.Description \line else \line Response.redirect ("\cf1 <!-- m --><a class="postlink" href="http://www.ebizsolutions.co.uk/ebiz2005/contact.htm">http://www.ebizsolutions.co.uk/ebiz2005/contact.htm</a><!-- m -->\cf0 ") \line end if \line set smtp = Nothing \line
^waht is all that????




\line


????

if you have issues posting it then upload the text file. I will take a look at it.I've posted exactly how it appears in the error window.then your syntax error is the "\line"

It should be on its own line after each of the occurances of it remove that then return to the next line. eg

For Each x In Request.Form
message = message & x & ": " & Request.Form(x) & CHR(10)
NextOK. I added a carriage return so that each line is definitely on its own, which has made a difference.

The error I now get is :-

Microsoft VBScript compilation error '800a0400'

Expected statement

/ebiz2005/files/formtomail.asp, line 3

\par
^


Any ideas ?yeah.... that shouldn't be there.

its not in the code you posted. or you didn't post it all.
 
Back
Top