?
Solved

while loop in asp email

Posted on 2007-08-07
4
Medium Priority
?
736 Views
Last Modified: 2013-11-05
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
Comment
Question by:imjusthere
  • 3
4 Comments
 
LVL 34

Accepted Solution

by:
Big Monty earned 1000 total points
ID: 19649984
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
 

Author Comment

by:imjusthere
ID: 19655728
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
 

Author Comment

by:imjusthere
ID: 19655777
I also forgot to change the values in the loop to recordset1 values.  I changed them but I'm getting the same results.
0
 

Author Comment

by:imjusthere
ID: 19656067
Never mind.  It's my sql that's not working properly.  The mail code works fine.  Thank you.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
Suggested Courses
Course of the Month13 days, 8 hours left to enroll

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question