2011-10-09 88 views
4
<% 
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="[email protected]" 
myMail.To="[email protected]" 
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 & "[email protected]" 

Set myMail2=CreateObject("CDO.Message") 
myMail2.Subject="Thanks for Contacting Us!" 
myMail2.From="[email protected]" 
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脚本的问题是,我需要检查电子邮件是否已发送,并根据结果重定向到错误或成功页面。如何检查是myMail.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 
代码

上述mymail2.Send =“”因为我在测试的东西,我知道我要的值更改为真或假,请用草率的答案!

在此先感谢!

回答

1

如果电子邮件地址具有有效的语法和SMTP服务器启动并运行,该Send方法不会抛出错误,甚至如果电子邮件地址不存在。

如果电子邮件到达目的地,我无法知道100% - 我能想到的一件事是在发送几秒钟后检查(使用FSO)SMTP根中的BadMailQueue文件夹,新条目意味着出了问题。

但是,当您使用外部邮件服务时,您必须联系他们并要求在交付失败时以某种方式收到通知。

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 
+0

您需要在重定向之前销毁对象,否则将不会发生。 – Dee

+0

是的,你是对的!我复制了这个问题。我会更新。谢谢。 –

+0

@Dee:这是为什么? – AnthonyWJones

相关问题