Batch E-mail

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • googletired
    New Member
    • Sep 2007
    • 30

    #1

    Batch E-mail

    Hello,

    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,

    G
  • DrBunchman
    Recognized Expert Contributor
    • Jan 2008
    • 979

    #2
    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

    Comment

    • markrawlingson
      Recognized Expert Contributor
      • Aug 2007
      • 346

      #3
      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.

      [code=html]
      <input type="checkbox" name="bSelected <% =oRs("ID") %>" value="true" />
      [/code]

      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.

      [code=asp]
      For Each oItem In Request.Form
      If InStr(oItem,"bS elected") > 0 And CBool( Request.Form( oItem ) ) = True Then
      sTemp = sTemp & Replace( Request.Form( oItem ), "bSelected" , "") & " "
      End If
      Next
      '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.
      aTemp = Split( sTemp )
      sSQL = "SELECT * FROM [tblDescriptions]"
      If IsArray( aTemp ) Then
      For i = 0 To UBound( aTemp )
      If i = 0 Then
      sSQL = sSQL & " WHERE ID = " & CInt( aTemp( i ) )
      Else
      sSQL = sSQL & " OR ID = " & CInt( aTemp( i ) )
      End If
      Next
      ElseIf aTemp <> Empty Then
      sSQL = sSQL & " WHERE ID = " & CInt( aTemp( i ) )
      End If
      Set oRs = Server.CreateOb ject("ADODB.Rec ordSet")
      oRs.Open sSQL, Your_Connection , adOpenStatic, adLockOptimisti c, adCmdText
      Do Until oRs.EOF = True
      sMessage = sMessage & oRs("sTitleOfIt em") & VbCRLF
      sMessage = sMessage & "The Item information goes here..."
      oRs.MoveNext
      Loop
      oRs.Close
      Set oRs = Nothing
      [/code]

      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.

      Sincerely,
      Mark

      Comment

      • googletired
        New Member
        • Sep 2007
        • 30

        #4
        Thanks for the insight Mark,

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

        G.

        Comment

        • markrawlingson
          Recognized Expert Contributor
          • Aug 2007
          • 346

          #5
          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.

          Sincerely,
          Mark

          Comment

          • googletired
            New Member
            • Sep 2007
            • 30

            #6
            Examples would be much apreciated. Using XML XSL ASP

            G.

            Comment

            • markrawlingson
              Recognized Expert Contributor
              • Aug 2007
              • 346

              #7
              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
              Code:
              <document>
                 <message>some message</message>
                 <message>some message</message>
                 <message>some message</message>
              </document>
              2) The page to display the selections to the user

              [code=asp]
              <%
              Set oXML = Server.CreateOb ject("msxml2.DO MDocument")
              oXML.async = true
              oXML.Load(Serve r.MapPath("/path/to/doc.xml"))
              Set oMessages = oXML.DocumentEl ement.GetElemen tsByTagName("me ssage")
              For i = 0 To oMessages.Lengt h - 1
              %>
              <input type="checkbox" name="bSelected <% =i %>" value="true" />
              <!-- do whatever else you need to do, maybe some descriptive message, or wrap this inside table tags, etc.
              <%
              Next
              %>
              [/code]

              3) Parse the information, retrieving the message node information according to what the user chose

              [code=asp]
              For Each oItem In Request.Form
              If InStr(oItem,"bS elected") > 0 And CBool( Request.Form( oItem ) ) = True Then
              sTemp = sTemp & Replace( Request.Form( oItem ), "bSelected" , "") & " "
              End If
              Next
              '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.
              aTemp = Split( sTemp )
              'open the XML document and retrieve our list of message nodes
              Set oXML = Server.CreateOb ject("msxml2.DO MDocument")
              oXML.async = true
              oXML.Load(Serve r.MapPath("/platform/platform.xml"))
              Set oMessages = oXML.DocumentEl ement.GetElemen tsByTagName("me ssage")
              '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.
              If IsArray( aTemp ) Then
              For i = 0 To UBound( aTemp )
              sEmailBody = sEmailBody & oMessages.Item( aTemp( i ) ).Text & VbCRLF
              Next
              ElseIf aTemp <> Empty Then
              sEmailBody = oMessages.Item( aTemp( i ) ).Text
              End If
              Set oXML = Nothing
              [/code]

              Hope that helps guide you in the right direction.

              Sincerely,
              Mark

              Comment

              • googletired
                New Member
                • Sep 2007
                • 30

                #8
                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,

                G.

                Comment

                Working...