ASP实现在提交表单到数据库的同时发邮件通知源码 5
展开全部
'定义几个常量(邮件发件人的相关信息)
Const aEmailSmtp="smtp.163.com" '发邮件的smtp服务器
Const aEmailUserName="xxx" '用于在邮件中显示的发件人名称(此处可随便填写,但有些邮局系统不支持显示此信息的,建议填写邮箱前缀,此处不影响邮件发送)
Const aEmailUserPass="password" '用于发送邮件的邮箱密码
Const aEmailName="xxx" '邮箱名称(此处不是邮箱帐号,建议填写邮箱前缀)
Const aEmailSendUser="xxx@163.com" '邮箱帐号(此处才是邮箱帐号,用此邮箱进行邮件发送的)
Const aEmailReplyTo="xxx@163.com" '回邮件默认的邮箱(用户如直接回复邮件时,默认回复到此邮箱中,但同样有些邮局系统不支持的,此处不影响邮件发送)
'asp发邮件(利用jmail组件)
Sub F_mail(email_title,to_email,MailBody)
'参数email_title--邮件标题
'参数to_email--收件人邮箱
'参数MailBody--邮件内容(可以带html代码的哦)
Dim Attachment
Dim ToMailbcc
Dim MailAddress
Dim MailUserName
Dim MailPassWord
Dim MailName
Dim MailSend
Dim MailTitle
Dim MailNameStr
Dim MailContent
Dim URLAttachment
Dim ToMailcc
Dim MailFormat
Dim JMail
Dim Mail
MailAddress=aEmailSmtp
MailUserName=aEmailUserName
MailPassWord=aEmailUserPass
MailName=aEmailName
MailSend=aEmailSendUser
MailTitle=email_title
MailNameStr=email_title
Mail=to_email
URLAttachment = ""
Attachment = ""
ToMailbcc = ""
ToMailcc = ""
MailFormat = "html"
Set JMail = Server.CreateObject("JMail.Message")
JMail.Charset="utf-8"
JMail.silent=True
JMail.ContentType = "text/html"
JMail.ReplyTo = aEmailReplyTo
JMail.From = MailSend
Jmail.FromName = MailName
JMail.Subject = MailNameStr
JMail.AddRecipient Mail
If ToMailcc <> "" and Not IsNull(ToMailcc) Then JMail.AddRecipientCC ToMailcc
If ToMailbcc <> "" and Not IsNull(ToMailbcc) Then JMail.AddRecipientBCC ToMailbcc
If MailFormat = "html" Then
JMail.HTMLBody = MailBody
Else
JMail.Body = MailBody
End If
JMail.Priority = 3
If Attachment <> "" and Not IsNull(Attachment) Then JMail.AddAttachment(Attachment)
If URLAttachment <> "" and Not IsNull(URLAttachment) Then JMail.AddURLAttachment URLAttachment
If MailUserName <> "" Then JMail.MailServerUserName = MailUserName
If MailPassWord <> "" Then JMail.MailServerPassword = MailPassWord
flag=JMail.Send(MailAddress)
jmail.close
set jmail=nothing
End Sub
'调用方式如下:
orderid="12345" '这里定义一个变量表示订单号
useremail="11223344@qq.com" '这里是收件人的邮箱地址
emailbody="这里是邮件的内容,可以加入html代码的" '邮件内容
Call F_mail("你的订单号是:"&orderid,useremail,emailbody)
正如楼下所说,要使用asp发邮件,一般会用jmail这个邮件发送组件,也就是说你的服务器上要安装好这个组件才行。
至于你所说的,提交表单内容到数据库的同时发邮件,这个就简单了。
你在完成表单内容的数据库记录插入后,调用一下这个邮件发送代码即可。
例如下面这样写:
'现在开始往数据库里插入记录,把表单提交的内容入库
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from userorder",conn,1,3
rs.addnew
rs("username")=request.form("username")
rs("useremail")=request.form("useremail")
rs("orderid")=request.form("orderid")
rs("orderamount")=request.form("orderamount")
rs.update
rs.close
set rs=nothing
'上面已经完成了数据库的保存,下面开始发邮件通知
Call F_mail("你的订单号是:"&request.form("orderid"),request.form("useremail"),"这里是具体的邮件内容")
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询