ASP tokens - Variable inserting and pulling out from DB

Discussion in 'C#' started by acidutzu, Nov 20, 2008.

  1. #1
    Hello ,

    I'm trying to create a simple newsletter with templates.
    I got this problem and i can't find any solution:

    On the CDO i have : objEmail.HTMLbody = ors("content")

    Now the problem is this Ors("content") is a memo field in access db.

    Beside this recordset in the page (ors) i have also an objrs that pull the data from another table where the people subscribe to newsletter (ex objrs("Name"), Objrs("date") ...)

    My problem is i need to make a kind of token like :
    objrs("Name") = [Name] and this [Name] to be inserted like variable in the access db in order to get inside of ors("content")
    something like:

    Hello [Name]

    you get this email because you subscribed to our newsletter in [date]...

    I don't know if you got my point but if i insert inside of db something like : "&objrs("Name")&" when will send the email it will not run the variable ...


    just to understand better i will paste here the full code:

    
    <!--#include file="db.asp"-->
     <%
    Const adOpenKeyset = 1
    Const adLockReadOnly = 1
    Const adCmdTable = &H0002
    Set oRS = Server.CreateObject("ADODB.Recordset")
    oRS.Open "Select * FROM emails where id="&replace(request.Form("subject"), "show.asp?id=", "")&"",xDb_Conn_Str
    
    Set objRS = Server.CreateObject("ADODB.RecordSet")
    objRS.Open ""&request.Form("table")&"" , xDb_Conn_Str ,adOpenKeyset ,adLockReadOnly,adCmdTable
    
    
    
    While not objRS.EOF
    [fullname] = objRS("full_name")
     On Error Resume Next
    Set objEmail = CreateObject("CDO.Message")
    objEmail.From = "admin@website.net" 
    objEmail.To = objRS("email")
    objEmail.Subject = ors("title")
    objEmail.HTMLbody = ors("content")
    objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.website.net"
    objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = "1"
    objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "admin@website.net"
    objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
    objEmail.Configuration.Fields.Update
    objEmail.Send
    If Not err.number=0 Then
    Response.write "ERROR: " & err.Description
    err.Clear
    
    end if
    
    Response.Write ("message sent to " & objRS("email") & "<br>")
    	'move to next entry in database
    	objRS.MoveNext
    Wend
    Response.Write ("newsletter creation completed ")
    Set objEmail = Nothing%>
    
    
    Code (markup):

    i will appreciate any advice,

    thank you
     
    acidutzu, Nov 20, 2008 IP
  2. gangwisch

    gangwisch Peon

    Messages:
    66
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    here would be a quick solution/fix:
    dim txt as string
    txt = cstr(ors("content"))
    txt = replace(txt,"[Name]",ors("firstname") & " " & ors("LastName"))
    txt = replace(txt,"[Date]",cstr(Now()))
    objEmail.HTMLbody = txt

    Good Luck
     
    gangwisch, Dec 9, 2008 IP