我已经提供了一个HTML文件。当有人填写表格时发送它,它应该发送电子邮件到他们的邮件ID。如何在ASP中编写代码?
您的姓名:* 电子邮件:* 电话号码 您的留言:*答案 0 :(得分:3)
像这样使用CDOSYS: -
Dim oMsg : Set oMsg = CreateObject("CDO.Message")
oMsg.From = "Me <me@mymail.myserver.com>"
oMsg.To = "Bloke <bloke@somewere.com>"
oMsg.Subject = "Test"
oMsg.HTMLBody = "<html><body>Hello World</body></html>"
oMsg.Send
当然,您需要从存储用户个人资料的持久性商店中获取“收件人”字段,并从发布的字段中提供正文和正文。
您还需要在IIS应用程序上配置邮件设置,以便为CDO.Message对象提供默认配置。如果你不能使用这样的函数自己配置邮件设置: -
Function GetConfiguration()
Const cdoSendUsingMethod = "http://schemas.microsoft.com/cdo/configuration/sendusing"
Const cdoSMTPServer = "http://schemas.microsoft.com/cdo/configuration/smtpserver"
Const cdoSMTPServerPickupDirectory = "http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory"
Const cdoSMTPServerPort = "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
Const cdoSendUsingPickup = 1
Const cdoSendUsingPort = 2
Dim GetConfiguration : SetGetConfiguration = CreateObject("CDO.Configuration")
With GetConfiguration.Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "mysmtp.myserver.com"
.Item(cdoSMTPServerPort) = 25
.Update
End With
End Function
然后在调用send: -
之前将此行添加到代码主体中Set oMsg.Configuration = GetConfiguration()
只需调整GetConfiguration内容即可使用您的SMTP服务器主机名。
注意不要使用已弃用的CDONTS。
答案 1 :(得分:1)
我假设你使用的是ASP 3.0,你可以使用Cdonts.dll
代码:
cBody = Request.Form("Body")
cPara = = Request.Form("to")
<%@ Language=VBScript%>
<html>
<head>
<title>Email Sending</title>
</head>
<body>
<%
Dim cBody, n
For Each n In Request.Form
cBody = cBody & n & ": " & Request.Form(n) & chr(13)
Next
Set oCDO = Server.CreateObject("CDONTS.NewMail")
oCDO.From = "fernan@tudominio.com"
oCDO.To = "foc@tudominio.com"
oCDO.Subject = "Subject"
oCDO.Body = cBody
'oCDO.Cc = "resal@tudominio.com;webmaster@tudominio.com"
oCDO.Bcc = "quinqui@tudominio.com"
'oCDO.MailFormat = 0
oCDO.Send
Set oCDO = Nothing
Response.Write "¡Email Sent!!"
%>
</body>
</html>