2012-09-11 144 views
0

我覺得我在這裏錯過了一些東西..我已經添加了幾個不同的東西給vbscript來嘗試使它僅在提交按鈕被點擊而不是兩次時運行(第二頁加載然後提交),但它破壞了它或者沒有工作。任何幫助這個初學者程序員將不勝感激。如果你需要html,請告訴我。編輯:仍在尋求幫助! :(VBScript運行兩次,一次頁面加載,一次提交。只需要提交?

<% 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 = Request.form(example) 
mailTo = "example" 
mailSubject = "example" 
mailMessage = "example" 
mailServer = "example" 
mailUsername = "example" 
mailPassword = "example" 

Call sendEmail(mailFrom, mailTo, mailSubject, mailMessage, mailServer, mailUsername, mailPassword) 
%> 

回答

1

如果Request.form(example) = ""那麼無論是頁面不是一個表單提交的結果(或形式沒有這個數據已提交)左右;

if Request.form(example) <> "" then 
    'is a form submission 
    .. email code 
end if 

如果你想更準確地判別提交恆定的隱藏字段添加到表單

<input type="hidden" name="sendemail" value="1" /> 

,尋找Request.form("sendemail") = "1"

+0

我試過之前添加過,它似乎沒有工作。我把如果request.form(email)=「」then else'vbscript code'end if if?那是錯的嗎? – Control

+0

你引用了這個名字嗎? '的request.form( 「電子郵件」)'?如果是這樣,你需要編輯你的問題與代碼+ html –

+0

當我這樣做(隱藏領域),一切運行良好,我只是從來沒有收到電子郵件,可能不會發送它。 – Control

相關問題