Example ASP script for sending form mail using Jmail |
Form.asp : |
<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="county"> <option value="coder">Staffordshire <option value="coder">Shropshire <option value="coder">Lincolnshire </select><br> Favorite TV-show <textarea name="tv-show"></textarea><br> <input type="submit" value="Send"> </form> </body> </html> |
Now create your mail script page... Sendmail.asp: |
<% smtp_server_address = "10.2.0.81" On Error Resume Next 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" 'Doing things this way helps retain the form field order For i = 1 to (Request.Form.Count) body = body & Request.Form.Key(i) & ": " & Request.Form.Item(i) & vbcrlfNext JMail.Body = Body JMail.Priority = 1 If Not Jmail.Send(smtp_server_address) then ' There was an error - print the error log Response.write ("Error:<br>" & Jmail.log) Else ' The message has been sent - redirect to confirmation page Set JMail = Nothing Response.Redirect "mail_sent.asp" End If Set JMail = Nothing %> |
This script will work on all forms with as many fields as
you wish. Parts in bold need to be changed to suit your needs.
The SMTP server address can be viewed under the 'Properties'
of your domain in the hosting controller. 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") 'first protected page here response.redirect "nextpage.asp" 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... |
<% 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 bold need to be changed to suit your needs |