繁体   English   中英

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

[英]Email Won't Send in Classic ASP, But I Never Get An Error

我正在建立一个网站,人们可以在其中注册服务。 当他们提交信息时,它应该创建一个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 = …命令中的级联有问题。

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM