2011-10-09 62 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

相關問題