当前位置: 移动技术网 > IT编程>开发语言>.net > 网页不存在自动给管理员发邮件的ASP代码

网页不存在自动给管理员发邮件的ASP代码

2019年01月02日  | 移动技术网IT编程  | 我要评论
制作网站的时候通常会有当访客的一些错误操作或我们网站本身的缺陷,造成某个不存在的页面被访问,这时会出现404错误提示信息,如果是热心的访客可能会给你发一封邮件提示你,当时大部分时候是访客不会给我们

制作网站的时候通常会有当访客的一些错误操作或我们网站本身的缺陷,造成某个不存在的页面被访问,这时会出现404错误提示信息,如果是热心的访客可能会给你发一封邮件提示你,当时大部分时候是访客不会给我们发邮件的。用asp做一个实用的程序,当用户访问出现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"
            "https://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>

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网