'set up
variables
intErrNumber = objError.Number
strErrDescription = objError.Description
strErrSource = objError.Source
strServerPage = "http://" &
Request.ServerVariables("SERVER_NAME")
& Request.ServerVariables("SCRIPT_NAME") ' get the page on
which the error occurred
strCRLF = Chr(13) & Chr(10) 'create the paragraph break for
use in the
email message to the administrator
strFromName = "Script Error Function" 'Email from name
strFromAddress = "scripterrors@yourcompany.com"
strRemoteHost = "mailhandler.yourcompany.com"
strSubjectText = "Error Occurred on: " &
Request.ServerVariables("SERVER_Name")
' the subject for the email to the administrator
'set
up the first
part of the email message
strBodyText = "The following error has occurred at this
URL" _
& strCRLF _
& strCRLF _
& strServerPage _
& strCRLF _
& strCRLF _
& "Details are as follows:" _
& strCRLF _
& strCRLF _
&
"#########################################################################"
_
& strCRLF _
& "PAGE LEVEL SCRIPT ERROR DETAILS:" _
& strCRLF _
& strCRLF _
& "Error Number: " & intErrNumber _
& strCRLF _
& "Error Description: " & strErrDescription _
& strCRLF _
& "Error Source: " & strErrSource _
& strCRLF _
&
"#########################################################################"
& strCRLF
Response.Clear ' clear
the buffer (to remove all the html from the original page
before the error)
' now
start to create
the error message by inserting the html template for the top of the page
and the text
%>
<!--#include file
="errors-top.asp" -->
<P>An error
occurred in the execution of this ASP page:<BR><BR>
<strong> <a
href=<%=strServerPage%>><%=strServerPage%></a></strong><BR><BR><P>
<% ' begin displaying the script errors to the user %>
<P><B>Script / Page Error</B><BR>
1. Error Number: <%= intErrNumber %><BR>
2. Error Description: <%=strErrDescription%><BR>
3. Error Source: <%=strErrSource%><BR></P>
<%'#################
'write the querystring values to the bodytext variable (if
any)
strBodyText = strBodyText
& "QUERYSTRING VALUES (if any) FOLLOW: " &
strCRLF &
strCRLF
For each x in Request.QueryString 'loop through all the
querystring values
and write them to the email
strBodyText = strBodyText
& x & " : " & Request.QueryString(x)
& strCRLF
'add the name / value pair to the string
next
strBodyText = strBodyText & strCRLF &
"#########################################################################"
& strCRLF 'write out delimter for this section
'#################
'write the form values to the bodytext variable (if any)
strBodyText = strBodyText & "FORM VALUES (if any)
FOLLOW: "
& strCRLF & strCRLF
For each x in Request.Form' loop through all the form values
and write them
to the email
strBodyText = strBodyText
& x & " : " & Request.Form(x) & strCRLF 'add
the name / value pair to the string
next
strBodyText = strBodyText & strCRLF &
"#########################################################################"
& strCRLF 'write out delimter for this section
'################# 'write the session variable values to the
bodytext variable
(if any)
strBodyText = strBodyText & "SESSION VARIABLE VALUES
(if any) FOLLOW:
" & strCRLF & strCRLF
For Each sessitem in Session.Contents ' loop through all the
session variable
values and write them to the email
strBodyText = strBodyText
& sessitem & " : " & Session.Contents(sessitem)
& strCRLF 'add the name / value pair to the string
Next
'#########Begin Automated
Notification########### ......this routine uses ASP Mail, obviously you
can use your preferred mailing routine in place of this if
required
' create
the mail object
and assign the necessary properties
Set theMail = CreateObject("SMTPsvg.Mailer")
theMail.FromName = strFromName
theMail.FromAddress = strFromAddress
theMail.RemoteHost = strRemoteHost
theMail.AddRecipient "", "steve@epsilis.co.uk"
theMail.Subject = strSubjectText
theMail.BodyText = strBodyText
' attempt to send the mail and notify the client if it fails -
if it doesn't
then notify that the webmaster has been notified
if theMail.SendMail = false then 'the mail was not sent
correctly
if
theMail.Response
<> "" then 'the error was
strError = theMail.Response
else
strError = "Unknown"
end
if
strMsg
= "We
tried to notify support@epsilis.co.uk but a program failure
occured. Please
<a
href=""mailto:support@epsilis.co.uk?subject=Error on this
URL: " & strServerPage & """>
contact support</a>
with following information.
<BR><BR> Reason
for failure: " & strError
Response.Write strMsg
else 'the mail was
sent correctly
strMsg
= "We
have notified support@epsilis.co.uk of this error. No
further action is
required."
Response.Write strMsg
end if
'#########End Automated
Notification###########
'include file which
writes out concluding html%>
<!--#include file = "errors-bottom.asp" -->
<%'
clear the error list and STOP page execution
Err.Clear
Response.End