Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Replace words with database values for email
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

eggyfarts
Junior Member

New Zealand
200 Posts

Posted - 22 August 2003 :  20:54:22  Show Profile
Hi all,

OK, what I have been trying to do is mod a free newsletter script so that I can write a newsletter, and it replaces certain words with a value from the database. EG if I wrote this newsletter:


Hi,

Thanks for being the winner of my auction ##TITLE##. The reference number for this auction is:##REF##. Blah Blah Blah ##AMMOUNT## and some more garbage and so on and so on...

Sincerely,
WeeVaa


Now in the database, along with the customers email address is text fields called TITLE,REF and AMMOUNT. What I want to do is when the email goes to send, replace the values in the email with ## around them with the value from the DB. So replace ##TITLE## with database value TITLE, ##REF## with the db value REF and so on. Here is the code that is used to send the emails:


<%
Server.ScriptTimeout = 1000000
Set RS = Server.CreateObject("ADODB.Recordset")
Set RSBODY = Server.CreateObject("ADODB.Recordset")
SQL2 = "SELECT * from Settings"
RSBODY.Open SQL2, Conn, 1, 3

SQL = "SELECT Email, REF, PHONE, TITLE, AMMOUNT FROM List"
RS.open SQL, conn

Select Case RSBODY("Component")

Case "CDONTS"



	Do While Not RS.eof
		set mailObj = Server.CreateObject("CDONTS.NewMail")
		If (Request("Format") = "Text") Then
			mailObj.BodyFormat = 1
			mailObj.MailFormat = 1
		Else
			mailObj.BodyFormat = 0
			mailObj.MailFormat = 0
		End If
		mailObj.From = RSBODY("From_Email")
		mailObj.To = RS("Email")
		mailObj.Subject = Request("Subject")
		mailObj.Body = Request("Body")
		mailObj.Send  RS.movenext
	Loop


On the form that is sent to that page, the textarea containg the message is called body. I have been playing around with the replace function all morning and searching on google and here for some answers but I'm a bit stumped. I would really appreaciate it if someone could help me out here .

Thanks,
WeeVaa
www.phonesdirect.co.nz

Edited by - eggyfarts on 22 August 2003 21:41:50

Nikkol
Forum Moderator

USA
6907 Posts

Posted - 22 August 2003 :  21:05:37  Show Profile
so the textarea named "Body" contains the "blah blah ##TITLE## blah blah" and so forth? if so, inside your loop I would put something like:

strBody = Request("Body")
strBody = Replace(strBody,"##TITLE##",RS("TITLE"))
strBody = Replace(strBody,"##AMOUNT##",RS("AMOUNT"))
strBody = Replace(strBody,"##REF##",RS("REF"))
mailObj.Body = strBody

Nikkol ~ Help Us Help You | ReadMe | 3.4.03 fixes | security fixes ~
Go to Top of Page

eggyfarts
Junior Member

New Zealand
200 Posts

Posted - 22 August 2003 :  21:18:03  Show Profile
Yes, textarea is named body.

My code now looks like this:


<%
Server.ScriptTimeout = 1000000
Set RS = Server.CreateObject("ADODB.Recordset")
Set RSBODY = Server.CreateObject("ADODB.Recordset")
SQL2 = "SELECT * from Settings"
RSBODY.Open SQL2, Conn, 1, 3

SQL = "SELECT Email, REF, PHONE, TITLE, AMMOUNT FROM List"
RS.open SQL, conn

Select Case RSBODY("Component")

Case "CDONTS"


	Do While Not RS.eof
		set mailObj = Server.CreateObject("CDONTS.NewMail")
		If (Request("Format") = "Text") Then
			mailObj.BodyFormat = 1
			mailObj.MailFormat = 1
		Else
			mailObj.BodyFormat = 0
			mailObj.MailFormat = 0
		End If
		mailObj.From = RSBODY("From_Email")
		mailObj.To = RS("Email")
		mailObj.Subject = Request("Subject")
			strBody = Request("Body")
			strBody = Replace(strBody,"##TITLE##",RS("TITLE"))
			strBody = Replace(strBody,"##AMMOUNT##",RS("AMMOUNT"))
			strBody = Replace(strBody,"##REF##",RS("REF"))
		mailObj.Body = Request("strBody")
		mailObj.Send  RS.movenext
	Loop


I have 2 test users setup in the DB, both with different email addresses and details, but they are both being sent blank emails now that I have added your little bit of code. The weird thing is that I put a
<% response.write strbody%>
in on the bit that says "Mail Sent" and it displays the full message, complete with the correct replacements for the last record in the DB (##TITLE##, ##REF## and ##AMMOUNT## have been replaced). So its replacing the values but not sending the body of the message.

Cheers,
WeeVaa.

Go to Top of Page

eggyfarts
Junior Member

New Zealand
200 Posts

Posted - 22 August 2003 :  22:06:35  Show Profile
Fixed it, heres what I changed:


<%
Server.ScriptTimeout = 1000000
Set RS = Server.CreateObject("ADODB.Recordset")
Set RSBODY = Server.CreateObject("ADODB.Recordset")
SQL2 = "SELECT * from Settings"
RSBODY.Open SQL2, Conn, 1, 3

SQL = "SELECT Email, REF, PHONE, TITLE, AMMOUNT FROM List"
RS.open SQL, conn

Select Case RSBODY("Component")

Case "CDONTS"


	Do While Not RS.eof
		set mailObj = Server.CreateObject("CDONTS.NewMail")
		If (Request("Format") = "Text") Then
			mailObj.BodyFormat = 1
			mailObj.MailFormat = 1
		Else
			mailObj.BodyFormat = 0
			mailObj.MailFormat = 0
		End If
		mailObj.From = RSBODY("From_Email")
		mailObj.To = RS("Email")
		mailObj.Subject = Request.Form("Subject")
			strBody = Request.Form("Body")
			strBody = Replace(strBody,"##TITLE##",RS("TITLE"))
			strBody = Replace(strBody,"##AMMOUNT##",RS("AMMOUNT"))
			strBody = Replace(strBody,"##REF##",RS("REF"))
		mailObj.Body = strBody
		mailObj.Send  RS.movenext
	Loop


Thanks for your help Nikkol, you always seem to be helping me out .

Cheers,
WeeVaa.

Go to Top of Page

Nikkol
Forum Moderator

USA
6907 Posts

Posted - 22 August 2003 :  22:08:13  Show Profile
that is because you are setting mailObj.Body=Request("strBody"). There is no such object to request. It should be mailObj.Body=strBody.

Nikkol ~ Help Us Help You | ReadMe | 3.4.03 fixes | security fixes ~
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.44 seconds. Powered By: Snitz Forums 2000 Version 3.4.07