簡體   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