电子邮件无法在传统ASP中发送,但我从未收到错误消息

时间:2018-07-31 16:32:30

标签: email asp-classic

我正在建立一个人们可以注册服务的网站。当他们提交信息时,它应该创建一个XMLHttpRequest并将数据发送到服务器上的.asp文件。然后,ASP应通过电子邮件将数据发送给我,并向用户发送确认电子邮件。

这是发送请求的代码(用JavaScript编写):

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
    if(this.readyState == 4 && this.status == 200){
            window.location = 'thankyou.html';
    }
};
xhttp.open("POST", "sendData.asp", true)
xhttp.setRequestHeader("Content-type", document.forms["SignupForm"])
xhttp.send("fname="+fname+"&lname="+lname+"&email="+email+"&width="+width+"&length="+length+"&depth="+depth+"&crnStp="+crnStp+"&jets="+jets+"&mirror="+mirror+"&rails="+rails)

这是随后对其进行处理的经典ASP:

response.expires=-1
Dim fname
Dim lname
Dim email
Dim width
Dim length
Dim depth
Dim crnStp
Dim jets
Dim mirror
Dim rails
fname=request.querystring("fname")
lname=request.querystring("lname")
email=request.querystring("email")
width=request.querystring("width")
length=request.querystring("length")
depth=request.querystring("depth")
crnStp=request.querystring("crnStp")
jets=request.querystring("jets")
mirror=request.querystring("mirror")
rails=request.querystring("rails")
Dim msg
Set msg = CreateObject("CDO.Message")
msg.Subject = "NewPoolSignUp"
msg.From = "robot@example.com"
msg.To = "myEmail@example.com"
msg.TextBody = fname & "," & lname & "," & email & "," & width & "," & length & "," & depth & "," & crnStp & "," & jets & "," & mirror & "," & rails
msg.Send
set msg = nothing
Dim msg
Set msg = CreateObject("CDO.Message")
msg.Subject = "Thank You For Joining Big Splash!"
msg.From = "robot@example.com"
msg.To = email
msg.CreateMHTMLBody = "https://example.com/sf/confEmail.html" 'An html page created, body of email should be = to page
msg.Send
set msg = nothing
response.write("done")

在给出答案时请保持礼貌,因为我是ASP新手。上面的所有代码都来自其他来源(尽管我修改了文件名和目录之类的东西)。

如上所述,代码没有给出错误,但我从未收到过电子邮件。有人可以帮我吗?

编辑:上面的代码确实给我一个错误。 (我不小心在其中插入了Response.End。)我删除了Response.End语句,并为端口,smtp服务器,用户名,密码等添加了配置设置。

我还从我的Gmail帐户(发送该帐户的帐户)收到一条警报,提示登录被阻止。我可能需要更改Gmail设置,以允许ASP访问该帐户。

编辑2:我更改了Gmail设置,并且正在接收电子邮件。但是它仍然会产生错误,当我查看电子邮件的内容时,它仅包含逗号而不包含变量。我认为msg.TextBody = …命令中的级联有问题。

1 个答案:

答案 0 :(得分:0)

您需要配置邮件服务器,否则您的代码将不知道从何处发送电子邮件。

msg.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = x
msg.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "your.exchange.server"
msg.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = x
msg.Configuration.Fields.Update
msg.Send