Ok, so my problem is this. I have a simple vbscript that sends an email when the form is submit. When it is in the code as follows, if sends the email (I receive the email in my inbox) undesirable twice: Once when the page loads, and once on submit:
<% Sub sendEmail(mailFrom, mailTo, mailSubject, mailMessage, mailServer, mailUsername, mailPassword)
Set MyMail = CreateObject("cdo.message")
MyMail.From = mailFrom
MyMail.To = mailTo
MyMail.Subject = mailSubject
MyMail.HTMLBody = mailMessage
MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = mailServer
MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = mailUsername
MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = mailPassword
MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
MyMail.Configuration.Fields.Update
MyMail.Send
Set MyMail = nothing
End Sub
Dim mailFrom, mailTo, mailSubject, mailMessage, mailServer, mailUsername, mailPassword
mailFrom = "example"
mailTo = "example"
mailSubject = "Email test"
mailMessage = "<html><body>example</body><html>"
mailServer = "example"
mailUsername = "example"
mailPassword = "example"
Call sendEmail(mailFrom, mailTo, mailSubject, mailMessage, mailServer, mailUsername, mailPassword)%>
So I figured I had to do something like this so it only sends once. Add a hidden field to the form under the submit button, and edit the code to this. The only problem is, when I do this, the form appears to submit properly and no errors occur, but I never get the email in my inbox! Any help would be GREATLY appreciated. I’m not the best at this stuff, and I’m still learning!:
<% if request.form("isSubmitted") = "yes" then
Sub sendEmail(mailFrom, mailTo, mailSubject, mailMessage, mailServer, mailUsername, mailPassword)
Set MyMail = CreateObject("cdo.message")
MyMail.From = mailFrom
MyMail.To = mailTo
MyMail.Subject = mailSubject
MyMail.HTMLBody = mailMessage
MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = mailServer
MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = mailUsername
MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = mailPassword
MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
MyMail.Configuration.Fields.Update
MyMail.Send
Set MyMail = nothing
End Sub
Dim mailFrom, mailTo, mailSubject, mailMessage, mailServer, mailUsername, mailPassword
mailFrom = "example"
mailTo = "example"
mailSubject = "Email test"
mailMessage = "<html><body>example</body><html>"
mailServer = "example"
mailUsername = "example"
mailPassword = "example"
Call sendEmail(mailFrom, mailTo, mailSubject, mailMessage, mailServer, mailUsername, mailPassword)
end if %>
Edit #1: This is my hidden field (I’ve also put the hidden field after the submit button to no avail.)
<input type="hidden" name="isSubmitted" id="isSubmitted" value="yes" />
<input type="submit" name="btnSubmit" id="btnSubmit" value="Submit" class="submit" />
Are you sure your form is doing a POST and not a GET ?
If it’s a GET request, you would need request.querystring(“isSubmitted”) instead
I would also put the check in a function.
Then you can use __ if IsSubmit() then __ in your code