ASP通过cdo发送邮件的代码
通过cdo发送邮件,无需组件支持。一般ASP空间即可实现在线发送。
我们能过下面这个例子说明其使用方法,比较简单,只需要更改相应的代码就可以了,具体是哪里,仔细看一下就明白:
<%
if request.form(“action”)=”add” then
form31=request.form(“form31”)
form32=request.form(“form32”)
form33=request.form(“form33”)
form34=request.form(“form34”)
form35=request.form(“form35”)
form36=request.form(“form36”)
form37=request.form(“form37”)
form38=request.form(“form38”)
form39=request.form(“form39”)
form40=request.form(“form40”)
form41=request.form(“form41”)
form42=request.form(“form42”)
form43=request.form(“form43”)
form44=request.form(“form44”)
form45=request.form(“form45”)
Dim iMsg
Dim iConf
Dim Flds
Dim strHTML
Dim strSmartHost
Const cdoSendUsingPort = 2
strSmartHost = “smtp.126.com”
userip = Request.ServerVariables(“HTTP_X_FORWARDED_FOR”)
If userip = “” Then userip = Request.ServerVariables(“REMOTE_ADDR”)
set iMsg = CreateObject(“CDO.Message”)
set iConf = CreateObject(“CDO.Configuration”)
Set Flds = iConf.Fields
With Flds
.Item(“http://schemas.microsoft.com/cdo/configuration/sendusing”) = cdoSendUsingPort
.Item(“http://schemas.microsoft.com/cdo/configuration/smtpserver”) = strSmartHost
.Item(“http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout”) = 10
.Item(“http://schemas.microsoft.com/cdo/configuration/smtpauthenticate”) = 1
.Item(“http://schemas.microsoft.com/cdo/configuration/sendusername”) = “username”
.Item(“http://schemas.microsoft.com/cdo/configuration/sendpassword”) = “password”
.Update
End With
strHTML = “<HTML>”
strHTML = strHTML & “<HEAD>”
strHTML = strHTML & “<BODY>”
strHTML = strHTML & “服务类型: ” & trim(form31) & “<br>”
strHTML = strHTML & “认证机构: ” & trim(form32) & “<br>”
strHTML = strHTML & “所在区域: ” & trim(form33) & “<br>”
strHTML = strHTML & “审核类型: ” & trim(form34) & “<br>”
strHTML = strHTML & “要求审核日期: ” & trim(form35) & “<br>”
strHTML = strHTML & “审核工厂名称: ” & trim(form36) & “<br>”
strHTML = strHTML & “详细地址: ” & trim(form37) & “<br>”
strHTML = strHTML & “产品: ” & trim(form38) & “<br>”
strHTML = strHTML & “工人人数: ” & trim(form39) & “<br>”
strHTML = strHTML & “联系人: ” & trim(form40) & “<br>”
strHTML = strHTML & “职位: ” & trim(form41) & “<br>”
strHTML = strHTML & “电话: ” & trim(form42) & “<br>”
strHTML = strHTML & “传真: ” & trim(form43) & “<br>”
strHTML = strHTML & “邮箱: ” & trim(form44) & “<br>”
strHTML = strHTML & “相关要求: ” & trim(form45) & “<br>”
strHTML = strHTML & “</BODY>”
strHTML = strHTML & “</HTML>”
With iMsg
Set .Configuration = iConf
.To =”gbcxm@163.com”
.From =”www.3code.cn<username@126.com>”
.Subject = “客户在线申请表单(” & now() &”)”
.HTMLBody = strHTML
.Send
End With
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing
Response.Write “<script>alert(‘留言成功,我们将尽快与您联系.’);location.href=’javascript:history.back()’;</script>”
end if
%>