<% ' Send Form Email Template ' ' ' ' DPaul Georgiades ' index.asp ' VBScript ' Send Email to mail server for subscription ' 2.0 ' ' 3/1/2001 - Created - David Jones, 19/1/2001 - Modified ' ' ' '############### This asp file will work with just about any HTML form '############### providing it has the following elements '
- the form should post to THIS page ' - a 'from email address' field called "SenderEmail" ' ' - there must be a submit button '############### Steps for using this template without needing to modify it '1 - Paste the HTML for the header, form and footer separately at the end of this file '2 - Set the variables as appropriate for the merchant '3 - Set the required fields for the form '4 - save the new ASP file in the merchant's ASP folder, along with any images, etc that it needs '############### Global Variables Dim Sendto Dim SendtoEmail Dim SenderEmail Dim Sender Dim Results Dim Error Error = 0 '############### Variables for this merchant ' You can use any input from the form to set a variable ' with the syntax 'request("bob")' where bob is the input name on the form Sendto = "PennyFarthingCycles" SendtoEmail = "john@skycamera.com.au" Sender = request("name") SenderEmail = request("email") Subject = "Website Enquiry" 'the starting value of the email message Message = "Form submitted: " & Now()& vblf 'the starting value of the message that is displayed to the user Results = "" '############### The Main Bit that does the job 'if the page is being opened after the submit button was pressed if request.form("cmd") ="sendmail" then 'then check that the sender email is valid if SenderEmail <> "" then If TestEmail(SenderEmail) = True Then Results = Results & "Invalid Email Address
" Error = 1 end if else Results = Results & "Please provide your email address
" Error = 1 end if CheckRequiredFields 'if there are no errors, build the email message and send it! (calls the Sendmail function from the sendmail include) if Error = 0 then '### if you want the email to include all fields then the next line should be: BuildMessage '### if you want only the fields that the user filled in then it should be: BuildMessageNoBlanks BuildMessageNoBlanks Set objNewMail = Server.CreateObject("CDONTS.NewMail") objNewMail.From = Sender & "<" & SenderEmail & ">" objNewMail.To = SendtoEmail objNewMail.Subject = Subject objNewMail.Body = Message objNewMail.Send Set objNewMail = Nothing Results = Results & "

Thankyou for your enquiry! - Your submission was successful. We will be in touch shortly." 'if there is an error, don't send the email, add a fail message to the results else Results = Results & "Your submission FAILED for the above reasons.
Please Try Again.


" end if end if '############### Check the Required Fields function Function CheckRequiredFields 'Then check for required fields - copy these next 4 lines for any required fields on the form if request("name") = "" then Results = Results & "Please provide your name
" Error = 1 end if End Function '############### Build Message function Function BuildMessage For ix = 1 to Request.Form.Count fieldName = Request.Form.Key(ix) fieldValue = Request.Form.Item(ix) Message = Message & vblf & fieldName & ": " & fieldValue Next End Function '############### Build Message No Blanks function Function BuildMessageNoBlanks For ix = 1 to Request.Form.Count fieldName = Request.Form.Key(ix) fieldValue = Request.Form.Item(ix) if fieldValue <> "" then Message = Message & vblf & fieldName & ": " & fieldValue Next End Function '############### Check for valid email function Function TestEmail(sEmail) TestEmail = False 'if the len is less than 5 then it can't be an email (i.e.: a@a.c) If Len(sEmail) <= 5 Then TestEmail = True End If 'If we find one and only one @, then the email address is good to go. If InStr(1, sEmail, "@", 1) < 2 Then TestEmail = True Else 'Must have a '.' too If InStr(1,sEmail, ".", 1) =0 Then TestEmail = True End If End If End Function 'HEADER HTML will be displayed both with the form and with any form results. '##################### Paste the HEADER HTML (every thing before the tag) below the next line %> SkyCamera.com.au
 
 
<% 'If the form has just been submitted then show the submission results if request.form("cmd") ="sendmail" then response.write Results else 'otherwise the page is being opened normally, so show the form '##################### Paste the FORM HTML content (usually starting with form tag) '##################### below the next line %>


John or Faye at SkyCamera

Phone
Fax
Email
1300 55 11 53
1300 55 11 59
john@skycamera.com.au

Submit an Enquiry

Name      
Email      
Phone      
Enquiry  
 

         



Acknowledgement: Colour Space's contribution to the design of the site. <% End if %>