- ASP - Miscellaneous
·Script Writers
·Database Display
·Response Objects
·Server Variables
·Random Events
·What's New?
Mail List


Form Mail with Input Validation (JMail)
There are many ways to get feedback from people using your site. One of the most popular methods is via an input form. Utilizing a form for input allows you to do most anything with the input, requiring certain fields to be filled out, sending the output to a database or creating mail. The following example will take user inputted values, verify that the fields have been filled out, and send an email message utilizing JMail. The version in the demo has the email commands commented out to prevent wide spread (ab)use of the server.
View the Output
Text View
Print View
Mail this Link
Download the Code

<title> Mail w/ Input Validation (JMail))</title>
<body bgcolor="#FFFFFF">
' Checks to see if the user inputted a value
' If so, remove leading and trailing blanks and upcase it
u_email= ucase(trim(request.form("u_email"))) 

' Grab the length of the email address inputted

' if the user has inputted a value start checking it
if trim(u_email) <> "" then 

' Loop that will check each character of the inputted value
' for the @ and the dot
for counter = 1 to email_len 
'If there is an @ set u_at to the position it was found in 
if mid(u_email,counter,1)="@" then 

' count the number of @'s

' if there is more than one add it to the message
if at_counter > 1 then message = message &"There appear to be multiple @'s in the email address<br>" end if

' if this is the 1st @ note the location in the string
if u_at = "" then
end if ' end check for first @
end if ' end check for the @ 

'If there is an dot (.) set u_dot to the position it was found in
if mid(u_email,counter,1)="." then 
if u_dot = "" then
end if 'end check for the first dot 
end if 'end check for the dot 


' Check to see if the dot comes after the @
' and that the first dot is not the last character
if (u_dot < u_at) or (len(u_email) <= u_dot+1) or ((u_dot-u_at) < 2) or (u_at < 2)then
message = message & "Email convention appears to be wrong <br>"
end if 'end check for dot after the @

' Scan the user input to see that all inputted values are either a letter A-Z,
' a number 0-9 or if the character is a . or and @.
for counter=1 to len(u_email) 
if (mid(u_email,counter,1) <> "/") and ((mid(u_email,counter,1) > chr(45)) and (mid(u_email,counter,1) < chr(58))) or ((mid(u_email,counter,1) > chr(63)) and (mid(u_email,counter,1) < chr(91))) then
' If it's an invalid charcter add it to the display message
message = message & "Invalid charcter "& mid(u_email,counter,1)& " found in email address <br>"
end if 'end check for invalid characters 
next 'end loop for invalid characters
end if 'end check for user input

' Check the email field for input if is blank
' then add to the display message
if (u_email = "") and (u_submit <> "") then
message= message & "Please enter an email address<br>"
end if

' Check the subject field for input if is blank
' then add to the display message
if (u_subject = "") and (u_submit <> "") then
message= message & "Please enter a subject<br>"
end if

' Check the message field for input if is blank
' then add to the display message
if u_body = "" and u_submit <> "" then
message= message & "Please enter a message"
end if

' If the email address is not OK than display the message(s)
' and show the text box for user input with the last value pre-filled
if message <> "" or u_email = "" then
response.write message %>

<form action="<%= request.servervariables("script_name") %>" method="post">
<input type="text" name="u_email" value="<%= lcase(u_email) %>">
<input type="text" name="u_subject" size="50" value="<%= u_subject %>">
<textarea rows="15" name="u_body" cols="50"><%= u_body %></textarea>
<input type="hidden" name="u_submit" value="Yes">
<input type="submit" value="Send Mail">
' If all seems ok begin processing the email
' Write the email contents to the browser 
response.write "<b>Email:</b><br> " & lcase(u_email) & "<br>" 
response.write "<br><b>Subject:</b><br> " & u_subject & "<br>"
response.write "<br><b>Message:</b><pre>" & u_body & "</pre>"

' This is the begining of the email creation and execution
' Remove the comments befor each statement that begins with Set or JMail
' to actually send the mail message

' Set JMail = Server.CreateObject ("JMail.SMTPMail") 
' This is you local SMTP server
' Change anyserver.ext to your server name
' JMail.ServerAddress = "mail.anyserver.ext:25"

' Declare the addressor
' JMail.Sender = "jmail_demo@anyserver.ext" 

' Get the recipients mailbox from a form (note the lack of a equal sign).
' This will send the message to address entered
' JMail.AddRecipient u_email

' Set the subject of the mail to inputted value
' JMail.Subject = u_subject

' Set the body of the mail to inputted value
' JMail.Body = u_body

' Send it...
' JMail.Execute 

end if %>




ASP: What's New? | Articles | Script Writers | Database Display | Read/Write
Server Variables | Response Objects | Random Events | Miscellaneous
HTML: Forms | Hyperlinks | Headers | Tables | Hyperlinks | Headers | Text Display
JavaScript: Document Info | Forms | Images | Navigation | Script Writers
CSS: Basics | Page Display | Text Display | Script Writers | Miscellaneous
  • 2014 michael kors
  • air max women 2013
  • 2014 michael kors
  • air max 2014
  • oakley glasses
  • oakley glasses

  • Maps: Map Script Writers | Bing Maps | Google Maps
  • bottes fr
  • ugg boot
  • Privacy Statement is hosted by
    Donate Food Online with a Mouse Click at
    Donate Land Online with a Mouse Click at
    © 1999 - 2019
    All Rights Reserved

  • Kids jordan 6 rings
  • Jordan retro 10
  • Jordan retro 3