2011-07-17 63 views
0

我參加了一個簡單的形式從網並把它放在一個網站,作爲一個接觸的形式使用,ALLS很好,它看起來還好,但是當我提交表單,我得到這個錯誤。 服務器對象錯誤ASP 0177:800401f3'ASP聯繫表格服務器對象錯誤ASP 0177:800401f3'

Server.CreateObject失敗

/new/contactusprocess.asp,線31

800401f3


這是代碼

<% 
Dim error 
error = 0 
For Each f In Request.Form 
    If Request.Form(f) = "" Then 
    error = 1 
    End If 
Next 
If error=1 Then 
    response.redirect "error.html" 
Else 
Dim f, emsg, mail_to, r, o, c, other 
fline = "_______________________________________________________________________"& vbNewLine 
hline = vbNewLine & "_____________________________________"& vbNewLine 
emsg = "" 

For Each f In Request.Form 
    If mid(f,1,1)<>"S" = True Then 'do not save if input name starts with S 
    emsg = emsg & f & " = " & Trim(Request.Form(f)) & hline 
    End If 
Next 

Set objNewMail = Server.CreateObject("CDONTS.NewMail") 
    objNewMail.From = Request("Email Address") 
    objNewMail.Subject = "Message from contact page (version: 1.0)" 
    objNewMail.To = mail_to 
    objNewMail.Body = emsg & fline 
    objNewMail.Send 
    Set objNewMail = Nothing 

response.redirect "thankyou.html" 
End if 
%> 

在此先感謝

回答

1

您所在的服務器沒有CDONTS庫。建議使用CDO.Message代替。 與您的主機確認他們支持從傳統ASP發送電子郵件。

用此代碼替換您的代碼(從包含CDONTS的行開始,最多包括Response.Redirect)。

Dim to, from, subj, body 
    from = Request("Email Address") 
    subj = "Message from contact page (version: 1.0)" 

    SendMail(subj, from, mail_to, emsg & fline) 
    Response.Redirect "thankyou.html" 
End If 

'******* a method to encapsulate our emailing functionality 
Sub SendMail(subject, from, to, body) 
    Dim sConfURL, cdoConfig, cdoMessage 

    Set cdoConfig = CreateObject("CDO.Configuration") 
    sConfURL = "http://schemas.microsoft.com/cdo/configuration/" 
    With cdoConfig.Fields 
     .Item(sConfURL & "sendusing") = 2 
     ,Item(sConfURL & "smtpserver") = "localhost" 
     .Item(sConfURL & "smtpserverport") = 25 
     .Update 
    End With 

    Set cdoMessage = CreateObject("CDO.Message") 

    With cdoMessage 
     Set .Configuration = cdoConfig 'may have to remove the Set if an error here. 
     .From = from 
     .To = to 
     .Subject = subject 
     .TextBody = body 
     .Send 
    End With 

    Set cdoMessage = Nothing 
    Set cdoConfig = Nothing 
End Sub 
+0

您好,謝謝,這是非常不同的,我的asp,我應該包含什麼html在這裏,以顯示窗體?我的html不適合您的更改,感謝您的幫助 – Sarah

+0

@Sarah:這裏沒有涉及HTML;我已經重構了答案,以幫助您粘貼到代碼中。你必須確保它適合你的應用程序。這意味着替換您的非工作的基於CDONTS的代碼。 –

+0

爲了完整的答案,值得一提的是CDONTS最後被包含在Windows 2000中,所以OP的主機在這裏沒有包含/支持它的問題。 –