<%
Dim sent
Dim YourName
Dim YourEmail
Dim YourMessage
Set myMail2=CreateObject("CDO.Message")
YourName = Trim(Request.Form("Name"))
YourEmail = Trim(Request.Form("Email"))
YourMessage = Trim(Request.Form("Message"))
Dim Body
Dim body2
Body = Body & "Their Name: " & VbCrLf & YourName & VbCrLf & VbCrLf
Body = Body & "Their Email: " & VbCrLf & YourEmail & VbCrLf & VbCrLf
Body = Body & "Their Message: " & VbCrLf & YourMessage & VbCrLf & VbCrLf
Set myMail=CreateObject("CDO.Message")
myMail.Subject="A New Enquiry!"
myMail.From="admin@musicalmatters.co.uk"
myMail.To="james@devine.eu"
myMail.TextBody=Body
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'Name or IP of remote SMTP server
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.1and1.com"
'Server port
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
myMail.Configuration.Fields.Update
myMail.Send
set myMail=nothing
body2="Thank you for contacting us!" & VbCrLf & "This is just a brief message to let you know your form was submitted successfully!"& VbCrLf & VbCrLf & "You may reply to this address, but you may not necessarily receive a reply, "& "you should receive a reply in 1-2 business day(s)!"& VbCrLf & "Thank you very much,"& VbCrLf & VbCrLf & "Musical Matters."& VbCrLf & "admin@musicalmatters.co.uk"
Set myMail2=CreateObject("CDO.Message")
myMail2.Subject="Thanks for Contacting Us!"
myMail2.From="admin@musicalmatters.co.uk"
myMail2.To=YourEmail
myMail2.TextBody=body2
myMail2.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'Name or IP of remote SMTP server
myMail2.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.1and1.com"
'Server port
myMail2.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
myMail2.Configuration.Fields.Update
myMail2.Send
If myMail2.Send="" Then
Response.Redirect("http://www.musicalmatters.co.uk/success.htm")
set myMail2=nothing
Else
Response.Redirect("http://www.musicalmatters.co.uk/error.htm")
set myMail2=nothing
End If
我的asp脚本的问题是我需要检查是否发送了电子邮件,并根据结果将它们重定向到错误或成功页面。
If myMail2.Send="" Then
Response.Redirect("http://www.musicalmatters.co.uk/success.htm")
set myMail2=nothing
Else
Response.Redirect("http://www.musicalmatters.co.uk/error.htm")
set myMail2=nothing
End If
在mymail2.Send =“”上方的代码中,因为我正在测试某些内容,我知道我必须将值更改为true或false,请匆忙解答您的答案!
提前致谢!
答案 0 :(得分:2)
似乎需要使用On Error语句。
On Error Resume Next
myMail2.Send
If Err.Number = 0 Then
set myMail2 = Nothing
Response.Redirect("http://www.musicalmatters.co.uk/success.htm")
Else
set myMail2 = Nothing
Response.Redirect("http://www.musicalmatters.co.uk/error.htm")
End If
答案 1 :(得分:1)
如果电子邮件地址的语法有效且SMTP服务器已启动并运行,则Send
方法永远不会抛出错误,即使电子邮件地址不存在。
如果电子邮件到达目的地,则无法100%知道 - 我可以想到的一件事是在几秒钟后检查(使用FSO)SMTP根目录中的BadMail
和Queue
个文件夹发送,如果它们包含新条目,则表示出现了问题。
但是,当您使用外部邮件服务时,您必须联系他们并要求在交付失败时以某种方式获得通知。