简体   繁体   中英

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

I am building a website where people can sign up for a service. When they submit their information, it should create an XMLHttpRequest and send the data to an .asp file on the server. The ASP should then email the data to me and email the user a confirmation email.

This is the code that sends the request (written in 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)

This is the classic ASP that then processes it:

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")

Please be courteous when giving answers, as I am new to ASP. All of the code above is from other sources (although I modified file names and directories and things like that).

As I said above, the code does not give an error but I never recieve the email. Could someone please help me with this?

EDIT: The above code does give me an error. (I had accidentally put Response.End in it.) I removed the Response.End statement and added configuration settings for ports, smtp server, username, password, etc. I still get an error.

I also get an alert from my Gmail account (the account being sent from) saying that a sign-in was blocked. I might need to change Gmail settings to allow the ASP to access the account.

EDIT 2: I changed the Gmail settings and I am recieving the email. But it still generates an error, and when I look at the contents of the email, it contains only commas and not the variables. I think there is something wrong with the concatenation in the msg.TextBody = … command.

You need to configure your mail server, otherwise your code won't know where to send the email from.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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