%@LANGUAGE="VBSCRIPT"%>
<%
OPTION EXPLICIT
Response.Buffer = true
'
'Generate the response and email the submission
'Assume webserver with asp and email but no database
'Set iEmail global variables
DIM MailMethod, SMTPServer, SMTPMailPickupDirectory, SMTPServerPort
'Global Settings (this marker may be used by the include directive to write out a master include)
MailMethod=0
'SMTPServer="servert"
'SMTPMailPickupDirectory="\\servert\mail\pickup"
'SMTPServerPort="25"
SMTPServer="127.0.0.1"
SMTPMailPickupDirectory="\\servert\mail\pickup"
SMTPServerPort="25"
'EOGlobal Settings
DIM sAddress, sSubject, sBody, fld
sAddress=Request.QueryString("e1")&"@"&Request.QueryString("e2")
IF Len(sAddress)>1 THEN
'There may be subsitutions and such in the first part rendering the last @ unwanted extra
IF Right(sAddress,1)="@" THEN sAddress=Left(sAddress,Len(sAddress)-1)
END IF
IF Len(sAddress)>1 THEN
Do While Len(sAddress)>1 AND Left(sAddress,1)=";"
IF Left(sAddress,1)=";" THEN sAddress=Mid(sAddress,2)
IF Left(sAddress,1)="@" THEN sAddress=Mid(sAddress,2)
sAddress=Trim(sAddress)
Loop
END IF
sSubject=Request.QueryString("subj")
sBody="Form Submitted "&FormatDateTime(Now, 1)&" "&FormatDateTime(Now, 3)&vbCRLF&vbCRLF
IF request.form("AllFields")<>"" THEN
'this is the new way of building the body in field order, but keeping the old way for backwards compatability
dim aFields, aPrompts, iField
aFields = split(request.form("AllFields"), ",")
aPrompts = split(request.form("AllPrompts"), ",")
For iField = 0 to uBound(aFields)
IF Not(fieldIsSystemField(aFields(iField))) THEN
IF Len(aPrompts(iField))>0 THEN
sBody=sBody&aPrompts(iField)&" = "&Request.Form(aFields(iField))&vbCRLF&vbCRLF
ELSE
sBody=sBody&aFields(iField)&" = "&Request.Form(aFields(iField))&vbCRLF&vbCRLF
END IF
IF Request.Form("rememberThese")<>"" THEN
Response.Cookies(aFields(iField))=Request.Form(aFields(iField))
Response.Cookies(aFields(iField)).Expires=(Date+365)
'Response.Write "Setting Cookie : "&fld&"
"
END IF
IF InStr(1,sAddress,"<"&aFields(iField)&">",1)>0 THEN
sAddress=Replace(sAddress,"<"&aFields(iField)&">",Request.Form(aFields(iField))&"",1,-1,1)
END IF
END IF
Next
ELSE
For Each fld In Request.Form
IF Not(fieldIsSystemField(fld)) THEN
sBody=sBody&fld&" = "&Request.Form(fld)&vbCRLF&vbCRLF
IF Request.Form("rememberThese")<>"" THEN
Response.Cookies(fld)=Request.Form(fld)
Response.Cookies(fld).Expires=(Date+365)
'Response.Write "Setting Cookie : "&fld&"
"
END IF
END IF
Next
END IF
sBody=sBody&vbCRLF&vbCRLF
sBody=sBody&"The Session number is "&Session.SessionID&vbCRLF
'sBody=sBody&"(NB: if there are multiple submissions from the same session, this would indicate the user has probably unintentionally submitted the form multiple times."&vbCRLF
sBody=sBody&"The IP was: "&Request.ServerVariables("LOCAL_ADDR")
IF Len(Request.ServerVariables("HTTP_X_FORWARDED_FOR"))>0 THEN
sBody=sBody&"The originating IP was (before routing): "&Request.ServerVariables("HTTP_X_FORWARDED_FOR")
END IF
'Do the email after the database save - we want the refID
'SendEmail "ComWebForms", sAddress, null, sSubject, sBody, false
'----------Access Database Save
DIM AccessFile, AccessPhysFile, fso, sAccessConn, oAccessConn, oRS, sSQL
DIM sFormName, ReferenceID
AccessFile="Data/FormData.mdb"
ReferenceID=""
Set fso=CreateObject("Scripting.FileSystemObject")
AccessPhysFile=Server.MapPath(AccessFile)
IF fso.FileExists(AccessPhysFile) THEN
sAccessConn = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & AccessPhysFile
Set oAccessConn=Server.CreateObject("ADODB.Connection")
oAccessConn.Open sAccessConn
IF InStr(sSubject,"(")>0 AND InStr(sSubject,")")>0 THEN
'this as original way Form (formname) Submission
sFormName=Mid(sSubject,InStr(sSubject,"(")+1)
sFormName=Left(sFormName,InStr(sFormName,")")-1)
ELSE
sFormName=sSubject
END IF
sSQL="CREATE TABLE ["&sFormName&"] ("
For Each fld In Request.Form
sSQL=sSQL&"["&fld&"] memo,"
Next
sSQL=Left(sSQL,Len(sSQL)-1) &")"
On Error Resume Next
oAccessConn.Execute sSQL
On Error Goto 0 : Err.Clear
sSQL="["&sFormName&"]"
Set oRS=Server.CreateObject("ADODB.Recordset")
Const adCmdTable = &H0002
oRS.Open sSQL, oAccessConn, 1, 2, adCmdTable
oRS.AddNew
For Each fld In Request.Form
On Error Resume Next
oRS(fld)=Request.Form(fld)
On Error Goto 0 : Err.Clear
Next
oRS.Update
On Error Resume Next
ReferenceID=oRS("RefID")
On Error Goto 0 : Err.Clear
oRS.Close: Set oRS=Nothing
Set oAccessConn=Nothing
END IF
DIM ReferenceMsg : ReferenceMsg=""
IF ReferenceID <> "" THEN
ReferenceMsg="
Your Reference Number is "&ReferenceID&"
" sSubject=sSubject&" Ref#"&ReferenceID END IF DIM sFromImpersonate sFromImpersonate=Request("email") 'IF sFromImpersonate="" THEN sFromImpersonate="ComWebForms" IF sFromImpersonate="" THEN sFromImpersonate="WebMaster@defence.gov.au" '23Nov07 Added this IF block - IF from address is in the to address ' then remove that address from the to and send another email to just that to with the from being the first part of the to 'eg the original from:Data successfully submitted
<%= ReferenceMsg %>An error has occurred attempting to send mail.
"
Response.Write "The server could not create the mail object. "
Response.Write "This is probably due to an error in configuration or the mail server may not be enabled.
"
Response.Write "The server error message is:
"&Err.Description&"
" Response.End END IF On Error GoTo 0 'create a new message configuration object Set objConfiguration = Server.CreateObject("CDO.Configuration") 'get a reference to the fields of the configuration object Set colFields = objConfiguration.Fields IF MailMethod=1 THEN colFields(cdoSendUsingMethod) = cdoSendUsingPickup colFields(cdoSMTPServerPickUpDirectory) = SMTPMailPickupDirectory ELSEIF MailMethod=2 THEN 'response.write SMTPServer&"