VBScript sends twice without hidden field, but never with it. Need help sending email

RealWaN

New Member
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:\[code\]<% Sub sendEmail(mailFrom, mailTo, mailSubject, mailMessage, mailServer, mailUsername, mailPassword)Set MyMail = CreateObject("cdo.message")MyMail.From = mailFromMyMail.To = mailToMyMail.Subject = mailSubjectMyMail.HTMLBody = mailMessageMyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = mailServerMyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = mailUsernameMyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = mailPasswordMyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25MyMail.Configuration.Fields.UpdateMyMail.SendSet MyMail = nothingEnd SubDim mailFrom, mailTo, mailSubject, mailMessage, mailServer, mailUsername, mailPasswordmailFrom = "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)%>\[/code\]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!:\[code\]<% if request.form("isSubmitted") = "yes" thenSub sendEmail(mailFrom, mailTo, mailSubject, mailMessage, mailServer, mailUsername, mailPassword)Set MyMail = CreateObject("cdo.message")MyMail.From = mailFromMyMail.To = mailToMyMail.Subject = mailSubjectMyMail.HTMLBody = mailMessageMyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = mailServerMyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = mailUsernameMyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = mailPasswordMyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25MyMail.Configuration.Fields.UpdateMyMail.SendSet MyMail = nothingEnd SubDim mailFrom, mailTo, mailSubject, mailMessage, mailServer, mailUsername, mailPasswordmailFrom = "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 %>\[/code\]
 
Back
Top