title: Sending email with recordset data
body: <p>I've got a classic ASP page listing some properties from a database and with each property there is a small contact form - to enable a user to 'request a callback' from the property agent associated with that property.</p>
  
  <p>However, whichever form I complete - the email to the agent always includes details of the first property on the page, rather than the property that the person is requesting a callback for.</p>
  
  <p>This is the code I have on the listings page (along with the contact form);</p>
  
  <pre><code>&lt;%
  Dim rspropertyresults
  Dim rspropertyresults_numRows
  
  Set rspropertyresults = Server.CreateObject("ADODB.Recordset")
  rspropertyresults.ActiveConnection = MM_dbconn_STRING
  
  rspropertyresults.Source = "SELECT * FROM VWTenantPropertiesResults ORDER BY ContentID DESC"
  
  rspropertyresults.CursorType = 0
  rspropertyresults.CursorLocation = 2
  rspropertyresults.LockType = 1
  rspropertyresults.Open()
  
  rspropertyresults_numRows = 0
  %&gt;
  
  &lt;% 
  sys_message = ""
  
  If (Request.Form("form_submit") &lt;&gt; "") Then
      Response.Write("&lt;h1&gt;Form Submitted&lt;/h1&gt;") 
      %&gt;&lt;!--#include file="docallback.asp"--&gt;&lt;%
  End If %&gt;
  
  &lt;body id="propertyresults"&gt;
  &lt;% If Not rspropertyresults.EOF Or Not rspropertyresults.BOF Then %&gt;
  &lt;% 
  While ((RepeatProperties__numRows &lt;&gt; 0) AND (NOT rspropertyresults.EOF)) 
  %&gt;
  &lt;div class="propertydetails"&gt;
  &lt;ul&gt;
  &lt;li class="price"&gt;&lt;% If (rspropertyresults("ContentPrice")) &lt;&gt; "" Then %&gt;&lt;%= FormatCurrency((rspropertyresults.Fields.Item("ContentPrice").Value), 2, -2, -2, -2) %&gt; PCM&lt;% End If ' price true %&gt;&lt;/li&gt;
  &lt;li class="address"&gt;&lt;%=varFullAddress%&gt;&lt;/li&gt;
  &lt;% If (rspropertyresults.Fields.Item("ContentDetails").Value) &lt;&gt; "" AND (rspropertyresults.Fields.Item("ContentDetails").Value) &lt;&gt; "&lt;p&gt;&lt;br /&gt;&lt;/p&gt;" Then %&gt;&lt;li&gt;&lt;%=StripHTML(rspropertyresults.Fields.Item("ContentDetails").Value)%&gt;&lt;/li&gt;&lt;% End If ' details true %&gt;
  &lt;/ul&gt;
  &lt;/div&gt;
  
  &lt;div class="propertyimage"&gt;
      &lt;a class="badge-callback" id="badge-callback&lt;%=(rspropertyresults.Fields.Item("ContentID").Value)%&gt;" title="Request Callback"  href="#"&gt;Request Callback&lt;/a&gt;
  
      &lt;div id="panel&lt;%=(rspropertyresults.Fields.Item("ContentID").Value)%&gt;"&gt;
          &lt;form action="default.asp" name="frmCallback" id="form_callback" method="post"&gt;
              &lt;fieldset&gt;
                  &lt;legend&gt;&lt;h2&gt;Request a callback&lt;/h2&gt;&lt;/legend&gt;
                  &lt;dl&gt;
                      &lt;dt&gt;&lt;label id="name"&gt;Name&lt;/label&gt;&lt;/dt&gt;
                      &lt;dd&gt;&lt;input id="form_input" type="text" name="txtName" /&gt;&lt;/dd&gt;
                      &lt;dt&gt;&lt;label id="email_address"&gt;Email&lt;/label&gt;&lt;/dt&gt;
                      &lt;dd&gt;&lt;input id="form_input" type="text" name="txtEmail" /&gt;&lt;/dd&gt;
                      &lt;dt&gt;&lt;label id="telephone"&gt;Telephone&lt;/label&gt;&lt;/dt&gt;
                      &lt;dd&gt;&lt;input id="form_input" type="text" name="txtTelephone" /&gt;&lt;/dd&gt;
                      &lt;input type="hidden" name="form_submit" value="submitted" /&gt;
                      &lt;dt&gt;&lt;input type="submit" value="Request a callback"&gt;&lt;/dt&gt;
                  &lt;/dl&gt;
              &lt;/fieldset&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;% 
    RepeatProperties__index=RepeatProperties__index+1
    RepeatProperties__numRows=RepeatProperties__numRows-1
    rspropertyresults.MoveNext()
  Wend
  %&gt;
  </code></pre>
  
  <p>I also have a docallback.asp page that handles the email sending;</p>
  
  <pre><code>&lt;%
      fldName         = replace(request.Form("fldName"),"'","")
      fldTelephone    = replace(request.Form("fldTelephone"),"'","")
      fldEmail        = replace(request.Form("fldEmail"),"'","")
  
      mBody = "&lt;html&gt;&lt;style&gt;body,p,td{font-family:arial;font-size:12px;}&lt;/style&gt;&lt;body&gt;"
      mBody = mBody &amp; "&lt;p&gt;A tenant has requested a call back for further information regarding the following property:&lt;/p&gt;"
  
      If (rspropertyresults.Fields.Item("ContentHouseNo").Value) &lt;&gt; "" Then
      varFullAddress = (rspropertyresults.Fields.Item("ContentHouseNo").Value) &amp;  " "
      End If
      varFullAddress = varFullAddress &amp; (rspropertyresults.Fields.Item("ContentStreet").Value)
      If (rspropertyresults.Fields.Item("ContentStreet2").Value) &lt;&gt; "" Then
      varFullAddress = varFullAddress &amp; " " &amp; (rspropertyresults.Fields.Item("ContentStreet2").Value)
      End If
      If (rspropertyresults.Fields.Item("ContentTown").Value) &lt;&gt; "" Then
      varFullAddress = varFullAddress &amp; " " &amp;  (rspropertyresults.Fields.Item("ContentTown").Value)
      End If
      If (rspropertyresults.Fields.Item("ContentArea").Value) &lt;&gt; "" Then
      varFullAddress = varFullAddress &amp; " " &amp;  (rspropertyresults.Fields.Item("ContentArea").Value)
      End If
      varFullAddress = varFullAddress &amp; " " &amp;  (rspropertyresults.Fields.Item("ContentPostCode").Value)
  
      mBody = mBody &amp; "&lt;p&gt;" &amp; varFullAddress &amp; "&lt;/p&gt;"
  
      mBody = mBody &amp; "&lt;p&gt;Their details are:&lt;/p&gt;"
  
      If request.Form("fldName") &lt;&gt; "" Then
          mBody = mBody &amp; "&lt;p&gt;Name: " &amp; request.Form("fldName") &amp; "&lt;br/&gt;"
      End If
  
      If request.Form("fldTelephone") &lt;&gt; "" Then
          mBody = mBody &amp; "Telephone: " &amp; request.Form("fldTelephone") &amp; "&lt;br/&gt;"
      End If
  
      If request.Form("fldEmail") &lt;&gt; "" Then
          mBody = mBody &amp; "Email: " &amp; request.Form("fldEmail") &amp; "&lt;/p&gt;"
      End If
  
      mBody = mBody &amp; "&lt;p&gt;" &amp; "&lt;strong&gt;" &amp; "http://www."&amp; varSiteDomain &amp; "&lt;/strong&gt;" &amp; "&lt;/p&gt;"
      mBody = mBody &amp; "&lt;/body&gt;&lt;/html&gt;"
  
      strMSSchema = "http://schemas.microsoft.com/cdo/configuration/"
      Set oCdoConfg = Server.CreateObject("CDO.Configuration")
      oCdoConfg.Fields.Item(strMSSchema &amp; "sendusing") = 1 
      oCdoConfg.Fields.Item(strMSSchema &amp; "smtpserver") = ""
      oCdoConfg.Fields.Item(strMSSchema &amp; "sendusername") = ""
      oCdoConfg.Fields.Item(strMSSchema &amp; "sendpassword") = ""
      oCdoConfg.Fields.Update     
  
      set oCdoMsg = server.createobject("CDO.Message")
      oCdoMsg.to = ""
      oCdoMsg.bcc = ""
      oCdoMsg.from = ""
      oCdoMsg.Subject = "A tenant has requested a callback about one of your properties"
      oCdoMsg.HTMLbody = mBody
      Set oCdoMsg.Configuration = oCdoConfg
      oCdoMsg.send
      set oCdoMsg = nothing
      set oCdoConfg = nothing 
  
      response.Redirect("default.asp")
  %&gt;
  </code></pre>
  
  <p>I wondered if anyone might be able to spot why the email is not sending the specific property details in the email?</p>
  
  <p>Apologies for the rather lengthy code.</p>
  
  <p>Thank you.</p>