By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,182 Members | 1,552 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,182 IT Pros & Developers. It's quick & easy.

Batch E-mail

P: 30

I have a content site. On this site a user can select a peice of content then have it e-mailed to there e-mail address. Then they continue the process for each item they wish to have e-maile dto them.

My question is. If i want them to be able to batch select the items they want to recieve instead of 1 at a time, would I have to go about this with a shopping cart routine? or is there a simpler way that I am just over looking?

Thanks in advance,

Feb 11 '08 #1
Share this Question
Share on Google+
7 Replies

Expert 100+
P: 979
Hi there,

I'd suggest storing the list of items in an array. Once they have finished selecting items the entire contents of the array could then be e-mailed.

Does this help?

Dr B
Feb 11 '08 #2

Expert 100+
P: 346
No it wouldn't have to be a shopping cart, though it may look like some shopping carts, asthetically speaking.

There are many solutions for any problem, and since I don't know a whole lot about how you've set this up, i'll give you one suggestion.

Providing that you have your descriptions set up in a row based table in your database, I would have a checkbox system with a form post. Allow the user to check of each item they would like info regarding, and then provide a button at the bottom "Email me the info!"

1. Create your checkboxes with a unique identifier attached to them.

Expand|Select|Wrap|Line Numbers
  1. <input type="checkbox" name="bSelected<% =oRs("ID") %>" value="true" />
Where oRs("ID") = the auto-increment field in your database table for the description of the item.

2. After the form has posted.. parse the information you recieve. Pass each of the IDs into your recordset to pull the information for each of the Items, loop through the recordset and create an email body of the information in which to send the user, pertinent to their choices.

Expand|Select|Wrap|Line Numbers
  1. For Each oItem In Request.Form
  2.    If InStr(oItem,"bSelected") > 0 And CBool( Request.Form( oItem ) ) = True Then
  3.       sTemp = sTemp & Replace( Request.Form( oItem ), "bSelected", "") & " "
  4.    End If
  5. Next
  6. 'sTemp will now be a string of all the IDs of the user's selection separated by a space so we can parse them into an array easily.
  7. aTemp = Split( sTemp )
  8. sSQL = "SELECT * FROM [tblDescriptions]"
  9. If IsArray( aTemp ) Then
  10.    For i = 0 To UBound( aTemp )
  11.       If i = 0 Then
  12.          sSQL = sSQL & " WHERE ID = " & CInt( aTemp( i ) )
  13.       Else
  14.          sSQL = sSQL & " OR ID = " & CInt( aTemp( i ) )
  15.       End If
  16.    Next
  17. ElseIf aTemp <> Empty Then
  18.    sSQL = sSQL & " WHERE ID = " & CInt( aTemp( i ) )
  19. End If
  20. Set oRs = Server.CreateObject("ADODB.RecordSet")
  21. oRs.Open sSQL, Your_Connection, adOpenStatic, adLockOptimistic, adCmdText
  22. Do Until oRs.EOF = True
  23.    sMessage = sMessage & oRs("sTitleOfItem") & VbCRLF
  24.    sMessage = sMessage & "The Item information goes here..."
  25.    oRs.MoveNext
  26. Loop
  27. oRs.Close
  28. Set oRs = Nothing
3. Create your mailer object, set the subject, from address, to address, set the message into the body, and send the email.

Hope this gives you some insight.

Feb 11 '08 #3

P: 30
Thanks for the insight Mark,

My site is comprised entirely of XSL/XML .ASP. no SQL.

Feb 11 '08 #4

Expert 100+
P: 346
No problem.

The same could be adapted to parse an XML document and send the info from it. And for that matter, .csv or even .txt or .xls files could be used to hold the information and parsed to send the required info... Or you could even just hold all the descriptive information within the .asp file and parse through a bunch of variables which hold that information - wouldn't recommend that, but it's possible. Probably the easiest way would be to create an access database to work off of, but if you'd prefer xml or some other method that's fine too.

Like I said, lots of ways to do it. If you want coding examples for any of the options above i'd be happy to oblige.

Feb 11 '08 #5

P: 30
Examples would be much apreciated. Using XML XSL ASP

Feb 11 '08 #6

Expert 100+
P: 346
I'm sure I don't have to explain how to write an XML document, but just for the sake of sakes (and other viewer's information/education)..

1) the .xml document
Expand|Select|Wrap|Line Numbers
  1. <document>
  2.    <message>some message</message>
  3.    <message>some message</message>
  4.    <message>some message</message>
  5. </document>
2) The page to display the selections to the user

Expand|Select|Wrap|Line Numbers
  1. <%
  2.    Set oXML = Server.CreateObject("msxml2.DOMDocument") 
  3.    oXML.async = true 
  4.    oXML.Load(Server.MapPath("/path/to/doc.xml"))
  5.    Set oMessages = oXML.DocumentElement.GetElementsByTagName("message")
  6.    For i = 0 To oMessages.Length - 1
  7. %>
  8.    <input type="checkbox" name="bSelected<% =i %>" value="true" />
  9.    <!-- do whatever else you need to do, maybe some descriptive message, or wrap this inside table tags, etc.
  10. <%
  11.    Next
  12. %>
3) Parse the information, retrieving the message node information according to what the user chose

Expand|Select|Wrap|Line Numbers
  1. For Each oItem In Request.Form
  2.    If InStr(oItem,"bSelected") > 0 And CBool( Request.Form( oItem ) ) = True Then
  3.       sTemp = sTemp & Replace( Request.Form( oItem ), "bSelected", "") & " "
  4.    End If
  5. Next
  6. 'sTemp will now be a string of all the IDs of the user's selection separated by a space so we can parse them into an array easily.
  7. aTemp = Split( sTemp )
  8. 'open the XML document and retrieve our list of message nodes
  9. Set oXML = Server.CreateObject("msxml2.DOMDocument") 
  10. oXML.async = true 
  11. oXML.Load(Server.MapPath("/platform/platform.xml"))
  12. Set oMessages = oXML.DocumentElement.GetElementsByTagName("message")
  13. 'Loop through the aTemp array, grabbing the information from the node as per the selections from the user which are numerical values held within the array. The numerical numbers represent the index of the message node within the xml document.
  14. If IsArray( aTemp ) Then
  15.    For i = 0 To UBound( aTemp )
  16.       sEmailBody = sEmailBody & oMessages.Item( aTemp( i ) ).Text & VbCRLF
  17.    Next
  18. ElseIf aTemp <> Empty Then
  19.    sEmailBody = oMessages.Item( aTemp( i ) ).Text
  20. End If
  21. Set oXML = Nothing
Hope that helps guide you in the right direction.

Feb 11 '08 #7

P: 30
Hi Mark,

Thanks for the example, I'll test a few ideas using your meothods today. The xml doc example wasn't required but I'm sure someone will find it useful. :)

Thanks again,

Feb 12 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.