2009-10-06 68 views
1

我有一个经典的ASP页面,列出了数据库中的一些属性,每个属性都有一个小的联系表单 - 使用户能够从属性代理中“请求回调”属性。发送带记录集数据的电子邮件

但是,无论我完成哪种表单 - 发送给代理的电子邮件始终包含页面上第一个属性的详细信息,而不是该用户请求回拨的属性。

这是我在列表页面上的代码(以及联系表格);

<% 
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 
%> 

<% 
sys_message = "" 

If (Request.Form("form_submit") <> "") Then 
    Response.Write("<h1>Form Submitted</h1>") 
    %><!--#include file="docallback.asp"--><% 
End If %> 

<body id="propertyresults"> 
<% If Not rspropertyresults.EOF Or Not rspropertyresults.BOF Then %> 
<% 
While ((RepeatProperties__numRows <> 0) AND (NOT rspropertyresults.EOF)) 
%> 
<div class="propertydetails"> 
<ul> 
<li class="price"><% If (rspropertyresults("ContentPrice")) <> "" Then %><%= FormatCurrency((rspropertyresults.Fields.Item("ContentPrice").Value), 2, -2, -2, -2) %> PCM<% End If ' price true %></li> 
<li class="address"><%=varFullAddress%></li> 
<% If (rspropertyresults.Fields.Item("ContentDetails").Value) <> "" AND (rspropertyresults.Fields.Item("ContentDetails").Value) <> "<p><br /></p>" Then %><li><%=StripHTML(rspropertyresults.Fields.Item("ContentDetails").Value)%></li><% End If ' details true %> 
</ul> 
</div> 

<div class="propertyimage"> 
    <a class="badge-callback" id="badge-callback<%=(rspropertyresults.Fields.Item("ContentID").Value)%>" title="Request Callback" href="#">Request Callback</a> 

    <div id="panel<%=(rspropertyresults.Fields.Item("ContentID").Value)%>"> 
     <form action="default.asp" name="frmCallback" id="form_callback" method="post"> 
      <fieldset> 
       <legend><h2>Request a callback</h2></legend> 
       <dl> 
        <dt><label id="name">Name</label></dt> 
        <dd><input id="form_input" type="text" name="txtName" /></dd> 
        <dt><label id="email_address">Email</label></dt> 
        <dd><input id="form_input" type="text" name="txtEmail" /></dd> 
        <dt><label id="telephone">Telephone</label></dt> 
        <dd><input id="form_input" type="text" name="txtTelephone" /></dd> 
        <input type="hidden" name="form_submit" value="submitted" /> 
        <dt><input type="submit" value="Request a callback"></dt> 
       </dl> 
      </fieldset> 
     </form> 
    </div> 
</div> 

<% 
    RepeatProperties__index=RepeatProperties__index+1 
    RepeatProperties__numRows=RepeatProperties__numRows-1 
    rspropertyresults.MoveNext() 
Wend 
%> 

我也有一个docallback.asp页面处理电子邮件发送;

<% 
    fldName   = replace(request.Form("fldName"),"'","") 
    fldTelephone = replace(request.Form("fldTelephone"),"'","") 
    fldEmail  = replace(request.Form("fldEmail"),"'","") 

    mBody = "<html><style>body,p,td{font-family:arial;font-size:12px;}</style><body>" 
    mBody = mBody & "<p>A tenant has requested a call back for further information regarding the following property:</p>" 

    If (rspropertyresults.Fields.Item("ContentHouseNo").Value) <> "" Then 
    varFullAddress = (rspropertyresults.Fields.Item("ContentHouseNo").Value) & " " 
    End If 
    varFullAddress = varFullAddress & (rspropertyresults.Fields.Item("ContentStreet").Value) 
    If (rspropertyresults.Fields.Item("ContentStreet2").Value) <> "" Then 
    varFullAddress = varFullAddress & " " & (rspropertyresults.Fields.Item("ContentStreet2").Value) 
    End If 
    If (rspropertyresults.Fields.Item("ContentTown").Value) <> "" Then 
    varFullAddress = varFullAddress & " " & (rspropertyresults.Fields.Item("ContentTown").Value) 
    End If 
    If (rspropertyresults.Fields.Item("ContentArea").Value) <> "" Then 
    varFullAddress = varFullAddress & " " & (rspropertyresults.Fields.Item("ContentArea").Value) 
    End If 
    varFullAddress = varFullAddress & " " & (rspropertyresults.Fields.Item("ContentPostCode").Value) 

    mBody = mBody & "<p>" & varFullAddress & "</p>" 

    mBody = mBody & "<p>Their details are:</p>" 

    If request.Form("fldName") <> "" Then 
     mBody = mBody & "<p>Name: " & request.Form("fldName") & "<br/>" 
    End If 

    If request.Form("fldTelephone") <> "" Then 
     mBody = mBody & "Telephone: " & request.Form("fldTelephone") & "<br/>" 
    End If 

    If request.Form("fldEmail") <> "" Then 
     mBody = mBody & "Email: " & request.Form("fldEmail") & "</p>" 
    End If 

    mBody = mBody & "<p>" & "<strong>" & "http://www."& varSiteDomain & "</strong>" & "</p>" 
    mBody = mBody & "</body></html>" 

    strMSSchema = "http://schemas.microsoft.com/cdo/configuration/" 
    Set oCdoConfg = Server.CreateObject("CDO.Configuration") 
    oCdoConfg.Fields.Item(strMSSchema & "sendusing") = 1 
    oCdoConfg.Fields.Item(strMSSchema & "smtpserver") = "" 
    oCdoConfg.Fields.Item(strMSSchema & "sendusername") = "" 
    oCdoConfg.Fields.Item(strMSSchema & "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") 
%> 

我想知道是否有人能够发现电子邮件为什么不发送电子邮件中的特定属性详细信息?

道歉为相当长的代码。

谢谢。

+0

在第二页中添加查询数据的SQL可能有助于调试。 – 2009-10-06 11:50:31

+0

@foriamstu我刚刚添加了包含在default.asp页面中的sql查询。 – doubleplusgood 2009-10-06 11:54:33

+0

字段'request.Form(“fldName”)' – 2009-10-06 11:35:38

回答

1

您似乎重复使用相同的结果集(rspropertyresults)来显示属性并发送电子邮件。

由于此记录集不接受ContentID作为参数(并且您不会将其发送),因此它将使用记录集中第一条记录上的属性发送电子邮件。

添加一个隐藏的输入ContentID到您的每一个形式,创建这个命令的附加记录:

SELECT * 
FROM VWTenantPropertiesResults 
WHERE ContentID = @ContentID 

,打开它,并用它来检索属性的细节:

cmdEmail = Server.CreateObject("ADODB.Command") 
rsEmail = Server.CreateObject("ADODB.Recordset") 

With cmdEmail 
    .ActiveConnection = MM_dbconn_STRING 
    .CommandText = "SELECT * FROM VWTenantPropertiesResults WHERE ContentID = ?" 
    .CommandType = 1 
    .Parameters.Append .CreateParameter("@ContentID", 3, 1, , request.Form("ContentID")) 
End With 

rsEmail.Open cmdEmail 
0

我不能完全知道你从哪里得到“rspropertyresults”,似乎没有查询。您可能需要确保数据可能在初始页面上找到,并存储并发送到doCallBack.asp页面(通过's或类似的方式)。

此外,您的输入框不会显示。对形式的两部分相同的名称也许有我丢失的东西,但我认为你要使用的东西,如:

fldName    = replace(request.Form("txtName"),"'","") 
fldTelephone = replace(request.Form("txtTelephone"),"'","") 
fldEmail   = replace(request.Form("txtEmail"),"'","") 
+0

@Amadiere输入框包含txtName,txtTelephone和txtEmail,如下所示; 。有一个SQL查询进一步在页面上获取项目(目前),只是选择所有相关的属性(包括电子邮件地址和contentid)。 – doubleplusgood 2009-10-06 11:45:44

+0

Foriamstu说,如果您不通过HTTP提交存储数据库中记录的ID,那么它将会丢失,您只需返回第一条记录即可查询返回。尝试添加隐藏字段以存储对该属性的一些引用,然后在您到达电子邮件部分时查询该字段。你一定需要做两个查询(或者在一个提交中存储所有数据)。 – Amadiere 2009-10-06 12:09:05

0

它看起来并不像你张贴内容识别到在表单中的docallback.asp页面,当你在docallback.asp页面上请求结果时,我猜你并没有按它过滤,这意味着你总是会得到第一个结果(而不是你想要)