ASP實現不存在的網頁就自動發送郵件

來源:互聯網
上載者:User

我們在製作網站的時候,通常會有當訪客的一些錯誤操作或我們網站本身的缺陷,造成某個不存在的頁面被訪問,這時會出現404錯誤提示資訊,如果是熱心的訪客可能會給你發一封郵件提示你,當時大部分時候是訪客不會給我們發郵件的。今天給大家介紹的這個程式是當我們的網站出現404錯誤提示時自動發送一封郵件給我們,代碼如下:

以下為引用的內容:
<% @language="vbscript" %>
<% Option Explicit %>
<%
    Dim strPage, strReferer, strMessage
    Dim objSMTP
    ' Log the offending page
    strPage = Request.ServerVariables("HTTP_URL")
    ' Log the referer
    strReferer = Request.ServerVariables("HTTP_REFERER")
    ' Set up the email component
    Set objSMTP = Server.CreateObject("JMail.Message")
    objSMTP.From = "you@yourdomain.com"
    objSMTP.FromName = "Your Domain"
    objSMTP.Subject = "404 Error Logged"
    objSMTP.AddRecipient("you@yourdomain.com")
    ' Write the message
    strMessage = "Requested page: " & strPage & vbCrLf & vbCrLf
    If strReferer <> "" Then
        strMessage = strMessage & "Referer: " & strReferer
    Else
        strMessage = strMessage "The visitor typed the address in"
    End If
    objSMTP.Body = strMessage
    ' Send the message
    objSMTP.Send("mail.jzxue.com")
    ' Tidy up
    objSMTP.ClearRecipients
    objSMTP.Close()
    Set objSMTP = Nothing
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
            "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
    <title>404 Page Not Found</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<h1>404 Page Not Found Error</h1>
<p>
Appropriate message here.
</p>
</body>
</html>
<% @language="vbscript" %>
<% Option Explicit %>
<%
    Dim strPage, strReferer, strMessage
    Dim objSMTP
    ' Log the offending page
    strPage = Request.ServerVariables("HTTP_URL")
    ' Log the referer
    strReferer = Request.ServerVariables("HTTP_REFERER")
    ' Set up the email component
    Set objSMTP = Server.CreateObject("JMail.Message")
    objSMTP.From = "you@yourdomain.com"
    objSMTP.FromName = "Your Domain"
    objSMTP.Subject = "404 Error Logged"
    objSMTP.AddRecipient("you@yourdomain.com")
    ' Write the message
    strMessage = "Requested page: " & strPage & vbCrLf & vbCrLf
    If strReferer <> "" Then
        strMessage = strMessage & "Referer: " & strReferer
    Else
        strMessage = strMessage "The visitor typed the address in"
    End If
    objSMTP.Body = strMessage
    ' Send the message
    objSMTP.Send("mail.jzxue.com")
    ' Tidy up
    objSMTP.ClearRecipients
    objSMTP.Close()
    Set objSMTP = Nothing
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
            "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
    <title>404 Page Not Found</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<h1>404 Page Not Found Error</h1>
<p>
Appropriate message here.
</p>
</body>
</html>

 請作者聯絡本站,及時附註您的姓名。聯絡郵箱:edu#chinaz.com(把#改為@)。

 



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.