0

这是发送电子邮件的 ASP 代码..

<%
'declare variables
Dim EmailFrom
Dim EmailTo
Dim Subject
Dim DealerName
Dim DealerNumber
Dim InvoiceNumber
Dim PONumber
Dim InvoiceDate
Dim ModelNumber
Dim SerialNumber
Dim ConditionofUnit
Dim ReasonforRMA
Dim OtherText
Dim ModelNumber2
Dim SerialNumber2
Dim ConditionofUnit2
Dim ReasonforRMA2
Dim OtherText2
Dim ModelNumber3
Dim SerialNumber3
Dim ConditionofUnit3
Dim ReasonforRMA3
Dim OtherText3
Dim ModelNumber4
Dim SerialNumber4
Dim ConditionofUnit4
Dim ReasonforRMA4
Dim OtherText4
Dim ModelNumber5
Dim SerialNumber5
Dim ConditionofUnit5
Dim ReasonforRMA5
Dim OtherText5
Dim ModelNumber6
Dim SerialNumber6
Dim ConditionofUnit6
Dim ReasonforRMA6
Dim OtherText6
Dim ModelNumber7
Dim SerialNumber7
Dim ConditionofUnit7
Dim ReasonforRMA7
Dim OtherText7
Dim ModelNumber8
Dim SerialNumber8
Dim ConditionofUnit8
Dim ReasonforRMA8
Dim OtherText8
Dim ModelNumber9
Dim SerialNumber9
Dim ConditionofUnit9
Dim ReasonforRMA9
Dim OtherText9
Dim ModelNumber10
Dim SerialNumber10
Dim ConditionofUnit10
Dim ReasonforRMA10
Dim OtherText10

' get posted data into variables
EmailFrom = Trim(Request.Form("EmailFrom")) 
EmailTo = "ouremail@domain.com"
Subject = "my subject"
DealerName = Trim(Request.Form("DealerName")) 
DealerNumber = Trim(Request.Form("DealerNumber")) 
InvoiceNumber = Trim(Request.Form("InvoiceNumber")) 
PONumber = Trim(Request.Form("PONumber")) 
InvoiceDate = Trim(Request.Form("InvoiceDate")) 
ModelNumber = Trim(Request.Form("ModelNumber")) 
SerialNumber = Trim(Request.Form("SerialNumber")) 
ConditionofUnit = Trim(Request.Form("ConditionofUnit"))
ReasonforRMA = Trim(Request.Form("ReasonforRMA")) 
OtherText = Trim(Request.Form("OtherText")) 
ModelNumber2 = Trim(Request.Form("ModelNumber2")) 
SerialNumber2 = Trim(Request.Form("SerialNumber2")) 
ConditionofUnit2 = Trim(Request.Form("ConditionofUnit2"))
ReasonforRMA2 = Trim(Request.Form("ReasonforRMA2")) 
OtherText2 = Trim(Request.Form("OtherText2")) 
ModelNumber3 = Trim(Request.Form("ModelNumber3")) 
SerialNumber3 = Trim(Request.Form("SerialNumber3")) 
ConditionofUnit3 = Trim(Request.Form("ConditionofUnit3"))
ReasonforRMA3 = Trim(Request.Form("ReasonforRMA3")) 
OtherText3 = Trim(Request.Form("OtherText3")) 
ModelNumber4 = Trim(Request.Form("ModelNumber4")) 
SerialNumber4 = Trim(Request.Form("SerialNumber4")) 
ConditionofUnit4 = Trim(Request.Form("ConditionofUnit4"))
ReasonforRMA4 = Trim(Request.Form("ReasonforRMA4")) 
OtherText4 = Trim(Request.Form("OtherText4")) 
ModelNumber5 = Trim(Request.Form("ModelNumber5")) 
SerialNumber5 = Trim(Request.Form("SerialNumber5")) 
ConditionofUnit5 = Trim(Request.Form("ConditionofUnit5"))
ReasonforRMA5 = Trim(Request.Form("ReasonforRMA5")) 
OtherText5 = Trim(Request.Form("OtherText5")) 
ModelNumber6 = Trim(Request.Form("ModelNumber6")) 
SerialNumber6 = Trim(Request.Form("SerialNumber6")) 
ConditionofUnit6 = Trim(Request.Form("ConditionofUnit6"))
ReasonforRMA6 = Trim(Request.Form("ReasonforRMA6")) 
OtherText6 = Trim(Request.Form("OtherText6")) 
ModelNumber7 = Trim(Request.Form("ModelNumber7")) 
SerialNumber7 = Trim(Request.Form("SerialNumber7")) 
ConditionofUnit7 = Trim(Request.Form("ConditionofUnit7"))
ReasonforRMA7 = Trim(Request.Form("ReasonforRMA7")) 
OtherText7 = Trim(Request.Form("OtherText7")) 
ModelNumber8 = Trim(Request.Form("ModelNumber8")) 
SerialNumber8 = Trim(Request.Form("SerialNumber8")) 
ConditionofUnit8 = Trim(Request.Form("ConditionofUnit8"))
ReasonforRMA8 = Trim(Request.Form("ReasonforRMA8")) 
OtherText8 = Trim(Request.Form("OtherText8")) 
ModelNumber9 = Trim(Request.Form("ModelNumber9")) 
SerialNumber9 = Trim(Request.Form("SerialNumber9")) 
ConditionofUnit9 = Trim(Request.Form("ConditionofUnit9"))
ReasonforRMA9 = Trim(Request.Form("ReasonforRMA9")) 
OtherText9 = Trim(Request.Form("OtherText9")) 
ModelNumber10 = Trim(Request.Form("ModelNumber10")) 
SerialNumber10 = Trim(Request.Form("SerialNumber10")) 
ConditionofUnit10 = Trim(Request.Form("ConditionofUnit10"))
ReasonforRMA10 = Trim(Request.Form("ReasonforRMA10")) 
OtherText10 = Trim(Request.Form("OtherText10")) 

Dim mail
Set mail = Server.CreateObject("CDONTS.NewMail") 
mail.To = EmailTo
mail.BodyFormat = 0
mail.MailFormat = 0
mail.From = EmailFrom
mail.Subject = Subject

mail.Body = "This is an email generated." & "<br>" & "<br>" & _
"<b>Dealer Name: </b>" & DealerName & "<br>" & _
"<b>Dealer Number: </b>" & DealerNumber & "<br>" & _
"<b>Invoice Number: </b>" & InvoiceNumber & "<br>" & _
"<b>PO Number: </b>" & PONumber & "<br>" & _
"<b>Invoice Date: </b>" & InvoiceDate & "<br>" & _
"<b>------ ITEM 1 ------</b><br>" & _
"<b>Model Number: </b>" & ModelNumber & "<br>" & _
"<b>Serial Number: </b>" & SerialNumber & "<br>" & _
"<b>Condition of Unit </b>" & ConditionofUnit & "<br>" & _
"<b>Reason for RMA: </b>" & ReasonforRMA & "<br>" & _
"<b>Other Text <i>(If Applicable)</i></b>: " & OtherText & "<br>" & _
"<b>------ ITEM 2 ------</b><br>" & _
"<b>Model Number: </b>" & ModelNumber2 & "<br>" & _
"<b>Serial Number: </b>" & SerialNumber2 & "<br>" & _
"<b>Condition of Unit </b>" & ConditionofUnit2 & "<br>" & _
"<b>Reason for RMA: </b>" & ReasonforRMA2 & "<br>" & _
"<b>Other Text <i>(If Applicable)</i></b>: " & OtherText2 & "<br>" & _
"<b>------ ITEM 3 ------</b><br>" & _
"<b>Model Number: </b>" & ModelNumber3 & "<br>" & _
"<b>Serial Number: </b>" & SerialNumber3 & "<br>" & _
"<b>Condition of Unit </b>" & ConditionofUnit3 & "<br>" & _
"<b>Reason for RMA: </b>" & ReasonforRMA3 & "<br>" & _
"<b>Other Text <i>(If Applicable)</i></b>: " & OtherText3 & "<br>" & _
"<b>------ ITEM 4 ------</b><br>" & _
"<b>Model Number: </b>" & ModelNumber4 & "<br>" & _
"<b>Serial Number: </b>" & SerialNumber4 & "<br>" & _
"<b>Condition of Unit </b>" & ConditionofUnit4 & "<br>" & _
"<b>Reason for RMA: </b>" & ReasonforRMA4 & "<br>" & _
"<b>Other Text <i>(If Applicable)</i></b>: " & OtherText4 & "<br>" & _
"<b>------ ITEM 5 ------</b><br>" & _
"<b>Model Number: </b>" & ModelNumber5 & "<br>" & _
"<b>Serial Number: </b>" & SerialNumber5 & "<br>" & _
"<b>Condition of Unit </b>" & ConditionofUnit5 & "<br>" & _
"<b>Reason for RMA: </b>" & ReasonforRMA5 & "<br>" & _
"<b>Other Text <i>(If Applicable)</i></b>: " & OtherText5 & "<br>" & _
"<b>------ ITEM 6 ------</b><br>" & _
"<b>Model Number: </b>" & ModelNumber6 & "<br>" & _
"<b>Serial Number: </b>" & SerialNumber6 & "<br>" & _
"<b>Condition of Unit </b>" & ConditionofUnit6 & "<br>" & _
"<b>Reason for RMA: </b>" & ReasonforRMA6 & "<br>" & _
"<b>Other Text <i>(If Applicable)</i></b>: " & OtherText6 & "<br>" & _
"<b>------ ITEM 7 ------</b><br>" & _
"<b>Model Number: </b>" & ModelNumber7 & "<br>" & _
"<b>Serial Number: </b>" & SerialNumber7 & "<br>" & _
"<b>Condition of Unit </b>" & ConditionofUnit7 & "<br>" & _
"<b>Reason for RMA: </b>" & ReasonforRMA7 & "<br>" & _
"<b>Other Text <i>(If Applicable)</i></b>: " & OtherText7 & "<br>" & _
"<b>------ ITEM 8 ------</b><br>" & _
"<b>Model Number: </b>" & ModelNumber8 & "<br>" & _
"<b>Serial Number: </b>" & SerialNumber8 & "<br>" & _
"<b>Condition of Unit </b>" & ConditionofUnit8 & "<br>" & _
"<b>Reason for RMA: </b>" & ReasonforRMA8 & "<br>" & _
"<b>Other Text <i>(If Applicable)</i></b>: " & OtherText8 & "<br>" & _
"<b>------ ITEM 9 ------</b><br>" & _
"<b>Model Number: </b>" & ModelNumber9 & "<br>" & _
"<b>Serial Number: </b>" & SerialNumber9 & "<br>" & _
"<b>Condition of Unit </b>" & ConditionofUnit9 & "<br>" & _
"<b>Reason for RMA: </b>" & ReasonforRMA9 & "<br>" & _
"<b>Other Text <i>(If Applicable)</i></b>: " & OtherText9 & "<br>" & _
"<b>------ ITEM 10 ------</b><br>" & _
"<b>Model Number: </b>" & ModelNumber10 & "<br>" & _
"<b>Serial Number: </b>" & SerialNumber10 & "<br>" & _
"<b>Condition of Unit </b>" & ConditionofUnit10 & "<br>" & _
"<b>Reason for RMA: </b>" & ReasonforRMA10 & "<br>" & _
"<b>Other Text <i>(If Applicable)</i></b>: " & OtherText10 & "<br>"
mail.Send 

' redirect to success page 
Response.Redirect("complete.html")
%>

因此,正如您所看到的,不是在每封电子邮件中发送所有 10 个项目,有谁知道我如何只能发送实际填写了值的项目?只需填写 1 项即可完成最多 10 项。

编辑:我把它改成这样:

Dim mail
Set mail = Server.CreateObject("CDONTS.NewMail") 
mail.To = EmailTo
mail.BodyFormat = 0
mail.MailFormat = 0
mail.From = EmailFrom
mail.Subject = Subject
If Request.Form("ModelNumber2") <> "" Then
mail.Body = "This is an email generated." & "<br>" & "<br>" & _
"<b>Dealer Name: </b>" & DealerName & "<br>" & _
"<b>Dealer Number: </b>" & DealerNumber & "<br>" & _
"<b>Invoice Number: </b>" & InvoiceNumber & "<br>" & _
"<b>PO Number: </b>" & PONumber & "<br>" & _
"<b>Invoice Date: </b>" & InvoiceDate & "<br>" & _
"<b>------ ITEM 1 ------</b><br>" & _
"<b>Model Number: </b>" & ModelNumber & "<br>" & _
"<b>Serial Number: </b>" & SerialNumber & "<br>" & _
"<b>Condition of Unit </b>" & ConditionofUnit & "<br>" & _
"<b>Reason for RMA: </b>" & ReasonforRMA & "<br>" & _
"<b>Other Text <i>(If Applicable)</i></b>: " & OtherText & "<br>" & _
"<b>------ ITEM 2 ------</b><br>" & _
"<b>Model Number: </b>" & ModelNumber2 & "<br>" & _
"<b>Serial Number: </b>" & SerialNumber2 & "<br>" & _
"<b>Condition of Unit </b>" & ConditionofUnit2 & "<br>" & _
"<b>Reason for RMA: </b>" & ReasonforRMA2 & "<br>" & _
"<b>Other Text <i>(If Applicable)</i></b>: " & OtherText2 & "<br>"

ElseIf Request.Form("ModelNumber2") <> "" And Request.Form("ModelNumber3") <> "" Then
mail.Body = "This is an email generated." & "<br>" & "<br>" & _
"<b>Dealer Name: </b>" & DealerName & "<br>" & _
"<b>Dealer Number: </b>" & DealerNumber & "<br>" & _
"<b>Invoice Number: </b>" & InvoiceNumber & "<br>" & _
"<b>PO Number: </b>" & PONumber & "<br>" & _
"<b>Invoice Date: </b>" & InvoiceDate & "<br>" & _
"<b>------ ITEM 1 ------</b><br>" & _
"<b>Model Number: </b>" & ModelNumber & "<br>" & _
"<b>Serial Number: </b>" & SerialNumber & "<br>" & _
"<b>Condition of Unit </b>" & ConditionofUnit & "<br>" & _
"<b>Reason for RMA: </b>" & ReasonforRMA & "<br>" & _
"<b>Other Text <i>(If Applicable)</i></b>: " & OtherText & "<br>" & _
"<b>------ ITEM 2 ------</b><br>" & _
"<b>Model Number: </b>" & ModelNumber2 & "<br>" & _
"<b>Serial Number: </b>" & SerialNumber2 & "<br>" & _
"<b>Condition of Unit </b>" & ConditionofUnit2 & "<br>" & _
"<b>Reason for RMA: </b>" & ReasonforRMA2 & "<br>" & _
"<b>Other Text <i>(If Applicable)</i></b>: " & OtherText2 & "<br>" & _
"<b>------ ITEM 3 ------</b><br>" & _
"<b>Model Number: </b>" & ModelNumber3 & "<br>" & _
"<b>Serial Number: </b>" & SerialNumber3 & "<br>" & _
"<b>Condition of Unit </b>" & ConditionofUnit3 & "<br>" & _
"<b>Reason for RMA: </b>" & ReasonforRMA3 & "<br>" & _
"<b>Other Text <i>(If Applicable)</i></b>: " & OtherText3 & "<br>"
'ElseIf Request.Form("ModelNumber4") = "" Then

'ElseIf Request.Form("ModelNumber5") = "" Then

'ElseIf Request.Form("ModelNumber6") = "" Then

'ElseIf Request.Form("ModelNumber7") = "" Then

'ElseIf Request.Form("ModelNumber8") = "" Then

'ElseIf Request.Form("ModelNumber9") = "" Then

'ElseIf Request.Form("ModelNumber10") = "" Then
Else
mail.Body = "This is an email generated." & "<br>" & "<br>" & _
"<b>Dealer Name: </b>" & DealerName & "<br>" & _
"<b>Dealer Number: </b>" & DealerNumber & "<br>" & _
"<b>Invoice Number: </b>" & InvoiceNumber & "<br>" & _
"<b>PO Number: </b>" & PONumber & "<br>" & _
"<b>Invoice Date: </b>" & InvoiceDate & "<br>" & _
"<b>------ ITEM 1 ------</b><br>" & _
"<b>Model Number: </b>" & ModelNumber & "<br>" & _
"<b>Serial Number: </b>" & SerialNumber & "<br>" & _
"<b>Condition of Unit </b>" & ConditionofUnit & "<br>" & _
"<b>Reason for RMA: </b>" & ReasonforRMA & "<br>" & _
"<b>Other Text <i>(If Applicable)</i></b>: " & OtherText & "<br>"
End If
mail.Send

但是当我填写 3 个项目时,它仍然只发送 2 个项目的电子邮件。我在这里想念什么?

4

1 回答 1

0

我会通过循环减少输入量...(最简单的方法是将“1”添加到第一组字段的末尾)自从我做了任何经典 ASP 以来已经有一段时间了,但是从记忆中这应该可以工作:

mail.Body = "This is an email generated." & "<br>" & "<br>" & _
"<b>Dealer Name: </b>" & DealerName & "<br>" & _
"<b>Dealer Number: </b>" & DealerNumber & "<br>" & _
"<b>Invoice Number: </b>" & InvoiceNumber & "<br>" & _
"<b>PO Number: </b>" & PONumber & "<br>" & _
"<b>Invoice Date: </b>" & InvoiceDate & "<br>"

for i = 1 to 10
    if trim(Request.Form("ModelNumber" & cstr(i))) <> "" then
        mail.Body += "<b>------ ITEM " & cstr(i) & " ------</b><br>" & _
            "<b>Model Number: </b>" & trim(Request.Form("ModelNumber" & cstr(i)) & "<br>" & _
            "<b>Serial Number: </b>" & trim(Request.form("SerialNumber" & cstr(i))  & "<br>" & _
             ...
    end if
next
于 2012-12-26T01:37:50.420 回答