Creating online forms -ASPMail


Each website hosted on AAPT's web servers has the ability to send Email from a web page. This is commonly used in applications where the web page vendor would like to recieve "feedback" or for basic online ordering/contact forms.
On our NT platform, the supported component for form-to-email is ASPMail.
Please note that we do not support the CDONTS.NEWMAIL object.

ASPMail Information.

  • ASPMail Version 4 is installed.
  • ASPMail is installed "globally" on the machine - eg: it will automatically be enabled with all web sites, and does not need to be installed for each client.
  • The ASPMail homepage is: http://www.serverobjects.com/products.htm#aspmail.
    Please reference this page, and the associated support site first if having difficulty.
  • The hostname to use for mail relay is: ntmailhost.hosting.connect.com.au
From the ASPMail web site:

"AspMail is used on more ASP installations than any other commercial or free product. Used on 1000's of Web sites around the world, this component allows you to send SMTP mail directly from a Web page. Versions 2.5x and > are 2-3 times faster than previous versions and have very low CPU utilization."

AspMail includes support for

  • SMTP (sending) Messages
  • Multiple File Attachments supporting MIME and UUencoding
  • PGP
  • US ASCII and ISO-8859-1 character sets
  • Priority, Urgent and Custom mail headers
  • MS Mail (including Exchange) priority headers
  • Reply-To, ConfirmReading and ReturnReceipt headers
  • Custom ContentType headers
  • Word Wrap (customizable)
  • Redundant SMTP servers
  • Multiple concurrent users
Important!
  • Please ensure that you always have a sender AND a receiver address specified in all scripts. Mail will not be send if these are absent.
    If you do not wish to hard-code these values in, please ensure you have some form of validation that is run on the users input before the form is submitted to pick up missed fields.




Working example code:

To make these scripts work, all you need to do is save the two files to a section of your website, change the sections in green to have "real" information, and then load "myform.asp" in a webbrowser.


-= The form =- (myform.asp)

     <%
     ' change these to reflect where form should go
     fromName="The _From_ Name here"
     fromAddress="sender@domain.com.au"
     toName="The _to_ name here"
     toAddress="recipient@domain.com.au"
     subject="Put your subject here"
     relay="ntmailhost.hosting.connect.com.au"
     %>
     <html>
     <head>
     <title>FormToBeMailed.asp</title>
     </head>
     <body>
     <form action="mailrespond.asp" method="GET">
       This is a demonstration form:<br>
       First Name : <input NAME="NameFirst" size="10"><br>
       Last Name : <input NAME="NameLast" size="10"><br>
       Country : <input NAME="Country" value="Australia" size="30"><br>
       State : <input NAME="State" MaxLength="2" size="3"><br>
       email copy to : <input NAME="emailcopy" MaxLength="20" size="40"><br>
       <input type="submit"><input type="reset">
       <% ' do not touch these lines. Needed to send mail! %>
       <input type="hidden" name="mail-from" value="<%=fromName%>">
       <input type="hidden" name="mail-fromAddress" value="<%=fromAddress%>">
       <input type="hidden" name="mail-to" value="<%=ToName%>">
       <input type="hidden" name="mail-toaddress" value="<%=toaddress%>">
       <input type="hidden" name="mail-subject" value="<%=subject%>">
       <input type="hidden" name="mail-relay" value="<%=relay%>">
       </form>
     </body>
   </html>
-= The responder code =- (mailrespond.asp)
   <html><head>
   <title>mailrespond.asp</title>
   </head><body bgcolor="#FFFFFF">
   <%
   ' ASPMail(tm) from http://www.serverobjects.com
   ' is not part of ASP per se,
   my_from=request("mail-fromName")
   my_fromAddress=request("mail-fromaddress")
   my_to=request("mail-toName")
   my_toAddress=request("mail-toaddress")
   my_subject=request("mail-subject")
   my_relay=request("mail-relay")
   Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
   Mailer.RemoteHost = my_relay
   Mailer.FromName = my_from
   Mailer.FromAddress = my_fromAddress
   Mailer.AddRecipient my_to, my_toaddress
   Mailer.Subject = my_subject

   for each whatever in request.querystring
      If instr(whatever,"mail-")=0 then
         Mailer.BodyText = whatever & "=" & vbcrlf
         Mailer.BodyText = request.querystring(whatever) & vbcrlf & vbcrlf
      end if
   next

   for each whatever in request.form
      If instr(whatever,"mail-")=0 then
         Mailer.BodyText = whatever & "=" & vbcrlf
         Mailer.BodyText = request.form(whatever) & vbcrlf & vbcrlf
      end if
   next

   my_emailcopy=request("emailcopy")
   If  my_emailcopy="" then
   else
      Mailer.AddRecipient "form filler",my_emailcopy
   end if

   If  Mailer.SendMail then
      Msg = "mail sent sucessfully!"
   Else
      Msg = "mail was not sent sucessfully"
   End If
   response.write Msg
   Response.Write(Mailer.Response)
   %>
   </body>
   </html>

   




Copyright © AAPT Limited