• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 742
  • Last Modified:

while loop in asp email

I'm trying to send email reguarding purchases made from our shopping cart.  I need to do a loop within the email because a user may order multiple items at once and I need to list them all.  I'm not sure if this can be done or how to go about it.  Below is the code I've tried.  It doesn't work, it ignores everything inside the loop.  If someone could give me some idea of how to go about this I would really appreciate it.

<%
Set objMail = Server.CreateObject("CDO.Message")

objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"


objMail.From = Session("eCartCheckoutForm_email") ' change this to an email address
objMail.To = "chrisw@databarinc.com" ' change this to your email address
objMail.Cc = "chrisw@databarinc.com"
objMail.Subject = Session("kt_Associate") & " Made A Purchase From Shopping Cart" ' change this to your subject
'Set the e-mail body format (HTMLBody=HTML TextBody=Plain)

'Set the e-mail body format (HTMLBody=HTML TextBody=Plain)
objMail.HTMLBody = "<font size=2 face=verdana>"
While ((Repeat_Recordset1__numRowsHL <> 0) AND (NOT Recordset1.EOF))
objMail.HTMLBody = objMail.HTMLBody & "Item Info " & "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Purchased at " & Now() & "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Company: " & WA_eCart_DisplayInfo(eCart1, "Name") & "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Item #: "& WA_eCart_DisplayInfo(eCart1, "ID") & "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Item Description: "& WA_eCart_DisplayInfo(eCart1, "Description")& "<br>"
objMail.HTMLBody = objMail.HTMLBody & "<br>"
    'Horizontal Looper version 3
    Repeat_Recordset1__indexHL=Repeat_Recordset1__indexHL+1
    Repeat_Recordset1__numRowsHL=Repeat_Recordset1__numRowsHL-1
    Recordset1.MoveNext()
    if len(nested_Recordset1)<=0 then
      nested_Recordset1 = 1
    end if
    if ((Repeat_Recordset1__numRowsHL <> 0) AND (NOT Recordset1.EOF) AND (nested_Recordset1 mod 4 = 0)) then
      Response.Write "</tr><tr>"
    end if
    nested_Recordset1 = nested_Recordset1 + 1
    'end horizontal looper version 3
  Wend
objMail.HTMLBody = objMail.HTMLBody & "Quantity: "& WA_eCart_DisplayInfo(eCart1, "Quantity") & "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Shipping: "& WA_eCart_GetRuleValueByName(eCart1, "Shipping", URLDecode("shippingcharge")) & "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Tax: "&WA_eCart_GetTax(eCart1)& "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Total: "& WA_eCart_GrandTotal(eCart1) & "<br>"
objMail.HTMLBody = objMail.HTMLBody & "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Billing Info " & "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Ordered By: " & Session("eCartCheckoutForm_firstname") & " " & Session("eCartCheckoutForm_lastname") & "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Card Type: "&Session("eCartCheckoutForm_cc_type")& "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Card #: "&Session("eCartCheckoutForm_cc_number")& "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Card Exp: "&Session("eCartCheckoutForm_exp_month")&" "&Session("eCartCheckoutForm_exp_year") &"<br>"
objMail.HTMLBody = objMail.HTMLBody & "Card CVV: "&Session("eCartCheckoutForm_cvv")& "<br>"
objMail.HTMLBody = objMail.HTMLBody & "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Contact Info "& "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Email: "&Session("eCartCheckoutForm_email")& "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Phone: "&Session("eCartCheckoutForm_phone")& "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Fax : "&Session("eCartCheckoutForm_fax")& "<br>"
objMail.HTMLBody = objMail.HTMLBody & "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Ship To: "& "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Name: "&Session("eCartCheckoutForm_shipping_firstname")& " "&Session("eCartCheckoutForm_shipping_lastname")&"<br>"
objMail.HTMLBody = objMail.HTMLBody & "Address: "&Session("eCartCheckoutForm_shipping_street1")& "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Address: "&Session("eCartCheckoutForm_shipping_street2")& "<br>"
objMail.HTMLBody = objMail.HTMLBody & "City: "&Session("eCartCheckoutForm_shipping_city")& "<br>"
objMail.HTMLBody = objMail.HTMLBody & "State: "&Session("eCartCheckoutForm_shipping_state_province")& "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Zip: "&Session("eCartCheckoutForm_shipping_postcode")& "</font>"

objMail.Send()

Set objMail = Nothing

%>
0
imjusthere
Asked:
imjusthere
  • 3
1 Solution
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
try changing it to a do-while loop:

do while not Recordset1.EOF
      'code to execute
     Recordset1.MoveNext
loop

also, you have code that displays what seems to me a certain number of items per row, but theres no table definition that i see anywhere.

B.D.
0
 
imjusthereAuthor Commented:
Nope, it still ignores everything in the loop.  All the rest of the info shows up on the email but nothing within the loop does.  If I take the loop out the information for the first record is displayed fine.  Any more ideas?

<%
Set objMail = Server.CreateObject("CDO.Message")

objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"


objMail.From = Session("eCartCheckoutForm_email")' change this to an email address
objMail.To = "chrisw@databarinc.com" ' change this to your email address
objMail.Cc = "chrisw@databarinc.com"
objMail.Subject = Session("kt_Associate") & " Made A Purchase From Shopping Cart" ' change this to your subject
'Set the e-mail body format (HTMLBody=HTML TextBody=Plain)

'Set the e-mail body format (HTMLBody=HTML TextBody=Plain)
objMail.HTMLBody = "<font size=2 face=verdana>"
do while not Recordset1.EOF
objMail.HTMLBody = objMail.HTMLBody & "Item Info " & "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Purchased at " & Now() & "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Company: " & WA_eCart_DisplayInfo(eCart1, "Name") & "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Item #: "& WA_eCart_DisplayInfo(eCart1, "ID") & "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Item Description: "& WA_eCart_DisplayInfo(eCart1, "Description")& "<br>"
objMail.HTMLBody = objMail.HTMLBody & "<br>"
  Recordset1.MoveNext
loop
objMail.HTMLBody = objMail.HTMLBody & "Quantity: "& WA_eCart_DisplayInfo(eCart1, "Quantity") & "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Shipping: "& WA_eCart_GetRuleValueByName(eCart1, "Shipping", URLDecode("shippingcharge")) & "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Tax: "&WA_eCart_GetTax(eCart1)& "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Total: "& WA_eCart_GrandTotal(eCart1) & "<br>"
objMail.HTMLBody = objMail.HTMLBody & "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Billing Info " & "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Ordered By: " & Session("eCartCheckoutForm_firstname") & " " & Session("eCartCheckoutForm_lastname") & "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Card Type: "&Session("eCartCheckoutForm_cc_type")& "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Card #: "&Session("eCartCheckoutForm_cc_number")& "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Card Exp: "&Session("eCartCheckoutForm_exp_month")&" "&Session("eCartCheckoutForm_exp_year") &"<br>"
objMail.HTMLBody = objMail.HTMLBody & "Card CVV: "&Session("eCartCheckoutForm_cvv")& "<br>"
objMail.HTMLBody = objMail.HTMLBody & "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Contact Info "& "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Email: "&Session("eCartCheckoutForm_email")& "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Phone: "&Session("eCartCheckoutForm_phone")& "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Fax : "&Session("eCartCheckoutForm_fax")& "<br>"
objMail.HTMLBody = objMail.HTMLBody & "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Ship To: "& "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Name: "&Session("eCartCheckoutForm_shipping_firstname")& " "&Session("eCartCheckoutForm_shipping_lastname")&"<br>"
objMail.HTMLBody = objMail.HTMLBody & "Address: "&Session("eCartCheckoutForm_shipping_street1")& "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Address: "&Session("eCartCheckoutForm_shipping_street2")& "<br>"
objMail.HTMLBody = objMail.HTMLBody & "City: "&Session("eCartCheckoutForm_shipping_city")& "<br>"
objMail.HTMLBody = objMail.HTMLBody & "State: "&Session("eCartCheckoutForm_shipping_state_province")& "<br>"
objMail.HTMLBody = objMail.HTMLBody & "Zip: "&Session("eCartCheckoutForm_shipping_postcode")& "</font>"

objMail.Send()

Set objMail = Nothing

%>
0
 
imjusthereAuthor Commented:
I also forgot to change the values in the loop to recordset1 values.  I changed them but I'm getting the same results.
0
 
imjusthereAuthor Commented:
Never mind.  It's my sql that's not working properly.  The mail code works fine.  Thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now