我必须为一个必须在ASP中的基本网站建立一个电子邮件,这是我一无所知的。
我已经构建了表单,并且所有内容似乎都无法正常运行,直到必须发送电子邮件为止,特别是此行:
objCDOMail.Send
浏览器中报告的错误是:
服务器错误500 - 内部服务器错误。有一个问题 您正在寻找的资源,无法显示。
有人会对为什么会发生这种情况有任何建议吗? 所有建议都将非常感谢!
完整代码如下:
<%
Dim name, email, comments
Dim objCDOMail 'The CDO object
name = Request.Form("name")
email = Request.Form("email")
comments = Request.Form("query")
message = "<HTML><table border='0' width='80%' bgcolor='#FFFFFF'><tr><td> " & _
"<p><strong>Name:</strong> " & name & _
"<p><strong>E-mail:</strong> " & email & _
"<p><strong>Comments:</strong> " & comments & _
"<p><hr></td></tr></table></html>"
Response.Write("" & message & "<br />")
Set objCDOMail = CreateObject("CDO.Message")
objCDOMail.From = "user@domain.co.uk"
objCDOMail.To = "user@domain.co.uk"
objCDOMail.Subject = ""
objCDOMail.HTMLBody = message
objCDOMail.Send
Set objCDOMail = Nothing
%>
答案 0 :(得分:0)
这可能与服务器有关。 IIS6和IIS7以不同的方式处理它。但是这应该可以帮助你解决它。这是我从现有网站上提取的代码并稍作修改。你必须增加你自己的目的:
Response.Buffer = True
Dim strBody
Dim objCDOMail
Dim strMyEmailAddress
Dim strCCEmailAddress
Dim strBCCEmailAddress
Dim strReturnEmailAddress
'THIS IS WHERE YOU CHANGE THE EMAIL ADDRESS
strMyEmailAddress = "you@yourdomain.com"
'strBCCEmailAddress = "bcc@yourdomain.com"
strReturnEmailAddress = Request.Form("Email")
strBody = strBody & "<br /><br /><span><strong>Name:</strong></span> " & Request.Form("name")
strBody = strBody & "<br /><br /><span><strong>E-mail:</strong></span> " & Request.Form("email")
strBody = strBody & "<br /><br /><span><strong>Company:</strong></span> " & Request.Form("company")
strBody = strBody & "<br /><br /><span><strong>Enquiry:</strong></span> " & Request.Form("enquiry")
strBody = strBody & "</p></div></body>"
If Len(strReturnEmailAddress) < 5 OR NOT Instr(1, strReturnEmailAddress, " ") = 0 OR InStr(1, strReturnEmailAddress, "@", 1) < 2 OR InStrRev(strReturnEmailAddress, ".") < InStr(1,strReturnEmailAddress, "@", 1) Then
strReturnEmailAddress = strMyEmailAddress
End If
Set objCDOMail = Server.CreateObject("CDO.Message")
objCDOMail.From = Request.Form("name") & " <" & strReturnEmailAddress & ">"
objCDOMail.To = strMyEmailAddress
objCDOMail.Cc = strCCEmailAddress
objCDOMail.Bcc = strBCCEmailAddress
objCDOMail.Subject = "Your Email Subject"
objCDOMail.HTMLBody = strBody '**This is for HTML Emails**
objCDOMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
objCDOMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")="localhost"
objCDOMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
objCDOMail.Configuration.Fields.Update
objCDOMail.Send
Set objCDOMail = Nothing
最后几行处理服务器并使用localhost发送邮件。您可以根据SMTP服务器进行更改。