Seem Internet Solutions Bargain Domain Name Registration and NT Web Hosting Packages

UK and US Domain Names Registrar and NT Web Hosting Packages
WorldPay Secure Shopping

See What Domain Names Registrations and Hosting Packages are in your Shopping CartView Cart

Domains Hosting FAQ / Support
Control Panels Dial Up Access Contact


Win2k Hosting Support

Script Examples

Example ASP script for sending formmail (uses Jmail)
Example ASP script for password protecting pages

Back to Support Index

Win2k Hosting Support


Example ASP script for sending formmail (uses Jmail)

First create your form page. Copy the following and paste it into a page called form.htm :

<html>
<head>
<title>emailform</title>
</head>
<body>
<form method="post" action="SendMail.asp">
Name <INPUT name="name" type="text"><br>
Email<INPUT name="Email" type="text"><br>
Company<INPUT name="company" type="text"><br>
Occupation <SELECT name="state">
<OPTION value="coder">Coder
<OPTION value="coder">Hacker
<OPTION value="coder">Developer
<OPTION value="coder">Guru
</SELECT><BR>
<INPUT type="submit" value="Send">
</form>
</body>
</html>

Now create your mail script page. Copy the following and paste the following into a new text file called sendmail.asp
Parts in red italics need to be changed to suit your needs .

<%
on error resume next

' the next four lines check the request came from your website

referred = lcase(request.servervariables("HTTP_HOST"))
if instr(lcase(referred),"yourdomainname") = 0 then
response.end
end if

' this bit creates the ASP component for sending the email

smtp_server_address = "localhost"
Response.Buffer = True
Set Jmail = Server.CreateOBject( "JMail.Message" )
Jmail.Logging = true
Jmail.Silent = true
JMail.From = "formresponse@yourdomain"
Jmail.AddRecipient "
sales@yourdomain"
JMail.Subject = "Form Response"

' this goes through the form and adds each section to the email

FOR EACH el IN Request.Form
body = body & el & ": " & Request.form(el) & vbcrlf
NEXT
JMail.Body = Body

' these lines send the email or show an error if it didn't work

if not Jmail.Send(smtp_server_address) then
Response.write ("Error:<br>" & Jmail.log)
else

Set JMail = Nothing

' the email was sent so redirect them to a page saying so

response.redirect "
successfulpage.htm"
end if
Set JMail = Nothing
%>

Create a standard html page called successfulpage.htm containing the message that the emai has been sent

Upload the three files you have into the same directory, then visit the form.htm page to test it. This script will work on all forms with as many fields as you wish.

Full details on how to use Jmail can be found here     

 top

 

 

Example ASP script for password protecting pages

To password protect a directory you can use the following method:

Create a page called index.asp as follows (replace guest and login with your own username and password)

<%
msg = ""
If Request("Submit")<>"" Then
If Request("username") = "
guest" and Request("password")="login" Then
Session("Valid") = Request("username")
response.redirect "
nextpage.asp"    'first protected page here
Else  msg = "Invalid username or password. Try again!"
End If
End If
%>
<html><head><title>Password Protect</title></head>
<body><form action="index.asp" method="post"><table>
<%If msg <> "" Then%>
<tr> <td colspan="2"><font color=red><%=msg%></font></td></tr>
<%End If%>
<tr> <td>UserName:</td> <td><input type="text" name="UserName"></td></tr>
<tr><td>Password:</td> <td><input type="Password" name="Password"></td></tr>
<tr><td colspan="2"><input type="submit" name="Submit"></td></tr>
</table></form></body></html>


On top of every ASP page you want to protect in the directory add the following function to the very top of the page:

<%If Session("Valid") = "" Then
Response.redirect "index.asp"
End If%>


Any page with this in it will not allow the user to view it unless they are logged in!

Parts in red italics need to be changed to suit your needs

Back to Support Index


Win2k Hosting Support

© 2008 Seem Internet Solutions Limited All rights reserved.
View our Privacy Policy - More Info About Us - Customers Comments - Vat Number 859720389