Sending CDONTS HTML email issue

B

BaWork

I have a web form where a client can select which site members to send
an email to.

This form is populated from the contents of the member table, so the
form can have 0-x names listed on it depending on member expiration dates.

When the form is submitted, the code loops through the form contents and
sends an email to those members that meet the selected criteria.

All this worked perfectly when I was sending text emails, but since I
changed, it sends the message correctly, but the last person gets
everyone else as well. For example, if I have three members (mem1, mem2
and mem3) to send emails to, here is what happens

mem1 gets the correctly formatted message

mem2 gets mem1's correctly formatted message plus mem2's message - one
right after the other.

mem3 gets mem1's correctly formated message, mem2's correctly formatted
message and mem3's message - one right after the other.

I'm not talking separate emails here, mem3 for example gets the body
content 3 times in one message, all correct for each member.

Here is the code, sorry it is long, but I didn't want to leave anything
out. I literally just swapped the plain text code for the HTML code and
added the necessary code in the send portion to send HTML rather than
plain text. I didn't change the logic at all.

Thanks

Brett

************** Code ***********************

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
on error resume next

iCount = Request.form("iCount")
iCount = iCount - 1

Set Conn = Server.CreateObject("ADODB.Connection")
conn.open "DSN=XXXXXXXXXXXX"

'Now, we want to loop through each form element

Dim iLoop
For iLoop = 0 to iCount

'Request form elements

mem_first = request.form(iLoop & ".mem_first")
mem_email = request.form(iLoop & ".mem_email")
email_action = request.form(iLoop & ".email_action")

'Send reminder email

If email_action = "reminder" then

MailBody = MailBody & "<html>" & vbCrlf & ""
MailBody = MailBody & "<body bgcolor=" & Chr(34) & "#FFCC66" & Chr(34) &
" text=" & Chr(34) & "#000000" & Chr(34) & " link=" & Chr(34) &
"#0033FF" & Chr(34) & " vlink=" & Chr(34) & "#0033FF" & Chr(34) & "
alink=" & Chr(34) & "#FF9900" & Chr(34) & ">" & vbCrlf & ""
MailBody = MailBody & "<p>&nbsp;</p>" & vbCrlf & ""
MailBody = MailBody & "<table width=" & Chr(34) & "600" & Chr(34) & "
border=" & Chr(34) & "3" & Chr(34) & " align=" & Chr(34) & "center" &
Chr(34) & " cellpadding=" & Chr(34) & "25" & Chr(34) & " cellspacing=" &
Chr(34) & "0" & Chr(34) & " bordercolor=" & Chr(34) & "#FF6600" &
Chr(34) & " bgcolor=" & Chr(34) & "#FFFFFF" & Chr(34) & ">" & vbCrlf & ""
MailBody = MailBody & "<tr>" & vbCrlf & ""
MailBody = MailBody & "<td valign=" & Chr(34) & "top" & Chr(34) & ">" &
vbCrlf & ""
MailBody = MailBody & "<p align=" & Chr(34) & "center" & Chr(34) &
"><b><font color=" & Chr(34) & "#FF6600" & Chr(34) & " size=" & Chr(34)
& "5" & Chr(34) & " face=" & Chr(34) & "Verdana, Arial, Helvetica,
sans-serif" & Chr(34) & ">Powerquotes Plus</font></b></p>" & vbCrlf & ""
MailBody = MailBody & "<p><font size=" & Chr(34) & "2" & Chr(34) & "
face=" & Chr(34) & "Verdana, Arial, Helvetica, sans-serif" & Chr(34) &
">From the desk of Kevin Eikenberry:</font></p>" & vbCrlf & ""
MailBody = MailBody & "<p><font size=" & Chr(34) & "2" & Chr(34) & "
face=" & Chr(34) & "Verdana, Arial, Helvetica, sans-serif" & Chr(34) &
">Your <strong>Powerquotes Plus</strong> membership will expire in one
week and I don’t want to lose you! </font></p>" & vbCrlf & ""
MailBody = MailBody & "<p><font size=" & Chr(34) & "2" & Chr(34) & "
face=" & Chr(34) & "Verdana, Arial, Helvetica, sans-serif" & Chr(34) &
">With only one week left, I want to make sure you have plenty of time
to <strong><a href=" & Chr(34) &
"http://www.powerquotesplus.net/renew_1.asp?mem_email=" & mem_email &
Chr(34) & ">renew your membership</a></strong> so you don’t miss
even one day of motivation and inspiration in your inbox.</font></p>" &
vbCrlf & ""
MailBody = MailBody & "<p><font size=" & Chr(34) & "2" & Chr(34) & "
face=" & Chr(34) & "Verdana, Arial, Helvetica, sans-serif" & Chr(34) &
">I’m sure if you spent some time looking through the private
membership site, worked through the questions, and applied all these
tools to your life, you’ll agree with me that this service is
filled with some incredible resources.</font></p>" & vbCrlf & ""
MailBody = MailBody & "<p><font size=" & Chr(34) & "2" & Chr(34) & "
face=" & Chr(34) & "Verdana, Arial, Helvetica, sans-serif" & Chr(34) &
">They can give your entire day a new outlook and some great actions to
take – right?</font></p>" & vbCrlf & ""
MailBody = MailBody & "<p><font size=" & Chr(34) & "2" & Chr(34) & "
face=" & Chr(34) & "Verdana, Arial, Helvetica, sans-serif" & Chr(34) &
">We are now offering recurring billing so you can pay a very small
investment each month to get this powerful information. For only .95 a
month, less than the price of a couple cups of coffee at Starbucks you
can have hundreds of dollars worth of information and help.</font></p>"
& vbCrlf & ""
MailBody = MailBody & "<p><font size=" & Chr(34) & "2" & Chr(34) & "
face=" & Chr(34) & "Verdana, Arial, Helvetica, sans-serif" & Chr(34) &
">Or you can save 21% by paying just for the full year.</font></p>" &
vbCrlf & ""
MailBody = MailBody & "<p><font size=" & Chr(34) & "2" & Chr(34) & "
face=" & Chr(34) & "Verdana, Arial, Helvetica, sans-serif" & Chr(34) &
">Get this… you will also get two weeks free for renewing to
<strong>Powerquotes Plus</strong>! After 2 weeks it is a miniscule
amount to have a personal coach at your beck-and-call.</font></p>" &
vbCrlf & ""
MailBody = MailBody & "<p><font size=" & Chr(34) & "2" & Chr(34) & "
face=" & Chr(34) & "Verdana, Arial, Helvetica, sans-serif" & Chr(34) &
"> I value you as a member.</font></p>" & vbCrlf & ""
MailBody = MailBody & "<p><font size=" & Chr(34) & "2" & Chr(34) & "
face=" & Chr(34) & "Verdana, Arial, Helvetica, sans-serif" & Chr(34) &
">And I am willing to send you some free gifts just for <strong><a
href=" & Chr(34) &
"http://www.powerquotesplus.net/renew_1.asp?mem_email=" & mem_email &
Chr(34) & ">renewing your membership right
away</a></strong>.</font></p>" & vbCrlf & ""
MailBody = MailBody & "<p><font size=" & Chr(34) & "2" & Chr(34) & "
face=" & Chr(34) & "Verdana, Arial, Helvetica, sans-serif" & Chr(34) &
">What are they?</font></p>" & vbCrlf & ""
MailBody = MailBody & "<p><font size=" & Chr(34) & "2" & Chr(34) & "
face=" & Chr(34) & "Verdana, Arial, Helvetica, sans-serif" & Chr(34) &
">Three Special Reports:</font></p>" & vbCrlf & ""
MailBody = MailBody & "<ul>" & vbCrlf & ""
MailBody = MailBody & "<li><font size=" & Chr(34) & "2" & Chr(34) & "
face=" & Chr(34) & "Verdana, Arial, Helvetica, sans-serif" & Chr(34) &
"><strong><em>25 Great Quotations for your Personal
Success</em></strong></font></li>" & vbCrlf & ""
MailBody = MailBody & "<li><em><font size=" & Chr(34) & "2" & Chr(34) &
" face=" & Chr(34) & "Verdana, Arial, Helvetica, sans-serif" & Chr(34) &
"><strong>25 Powerful Quotations for your Professional
Success</strong></font></em><font size=" & Chr(34) & "2" & Chr(34) & "
face=" & Chr(34) & "Verdana, Arial, Helvetica, sans-serif" & Chr(34) &
"> – keep them at your side – or at your desk.</font></li>"
& vbCrlf & ""
MailBody = MailBody & "<li><font size=" & Chr(34) & "2" & Chr(34) & "
face=" & Chr(34) & "Verdana, Arial, Helvetica, sans-serif" & Chr(34) &
"><strong><em>25 Great Quotations to Help Others Succeed</em></strong>.
We all know that the more we help others, the more we achieve ourselves.
This is the perfect tool to help those around you life lives full of
abundance and joy.</font></li>" & vbCrlf & ""
MailBody = MailBody & "</ul>" & vbCrlf & ""
MailBody = MailBody & "<p><font size=" & Chr(34) & "2" & Chr(34) & "
face=" & Chr(34) & "Verdana, Arial, Helvetica, sans-serif" & Chr(34) &
">One last mega success bribe/bonus for your free
trial…</font></p>" & vbCrlf & ""
MailBody = MailBody & "<ul>" & vbCrlf & ""
MailBody = MailBody & "<li><font size=" & Chr(34) & "2" & Chr(34) & "
face=" & Chr(34) & "Verdana, Arial, Helvetica, sans-serif" & Chr(34) &
"> An audio of live keynote speech entitled <strong><em>Unleashing Your
Potential in 2005</em></strong>. Groups pay up to 00 for my keynote
speeches and here is one for you for fr’ee. This keynote provides
ideas, tools and techniques to help you reach your personal and
professional goals in 2005. Along with rock solid techniques on goal
setting, I will share specific ideas to set you up for your best year
ever.</font></li>" & vbCrlf & ""
MailBody = MailBody & "</ul>" & vbCrlf & ""
MailBody = MailBody & "<p><font size=" & Chr(34) & "2" & Chr(34) & "
face=" & Chr(34) & "Verdana, Arial, Helvetica, sans-serif" & Chr(34) &
">Hopefully, the promise here is quite simple: <strong><a href=" &
Chr(34) & "http://www.powerquotesplus.net/renew_1.asp?mem_email=" &
mem_email & Chr(34) & ">Renew your membership today to Powerquotes
Plus</a></strong> and I will send you all of the free reports, along
with the live keynote recording.</font></p>" & vbCrlf & ""
MailBody = MailBody & "<p><font size=" & Chr(34) & "2" & Chr(34) & "
face=" & Chr(34) & "Verdana, Arial, Helvetica, sans-serif" & Chr(34) &
">It’s easy to renew. <strong><a href=" & Chr(34) &
"http://www.powerquotesplus.net/renew_1.asp?mem_email=" & mem_email &
Chr(34) & ">All you have to do is click on this private
link</a></strong> and you will automatically renew your membership
(starting with the 2 week no charge additional bonus) and the
“bribes” will be sent out to you right away.</font></p>" &
vbCrlf & ""
MailBody = MailBody & "<p><font size=" & Chr(34) & "2" & Chr(34) & "
face=" & Chr(34) & "Verdana, Arial, Helvetica, sans-serif" & Chr(34) &
">I look forward to doing my part to help you be more
successful!</font></p>" & vbCrlf & ""
MailBody = MailBody & "<p><img src=" & Chr(34) &
"http://www.powerquotesplus.net/images/kev_signature.jpg" & Chr(34) & "
width=" & Chr(34) & "53" & Chr(34) & " height=" & Chr(34) & "58" &
Chr(34) & "></p>" & vbCrlf & ""
MailBody = MailBody & "<p><font size=" & Chr(34) & "2" & Chr(34) & "
face=" & Chr(34) & "Verdana, Arial, Helvetica, sans-serif" & Chr(34) &
">Kevin Eikenberry<br><b>Powerquotes Plus</b> Founder</font></p>" &
vbCrlf & ""
MailBody = MailBody & "<p><font size=" & Chr(34) & "2" & Chr(34) & "
face=" & Chr(34) & "Verdana, Arial, Helvetica, sans-serif" & Chr(34) &
">p.s. <strong><a href=" & Chr(34) &
"http://www.powerquotesplus.net/renew_1.asp?mem_email=" & mem_email &
Chr(34) & ">Renew your membership today</a></strong> and receive all the
special bonus reports, audio and complimentary two weeks. Please put
some serious thought into what it is you are willing to do to make your
future a success. The tools you receive, and the membership benefits you
get, will help you accomplish whatever you want… on your own
terms.</font></p>" & vbCrlf & ""
MailBody = MailBody & "<p><font size=" & Chr(34) & "2" & Chr(34) & "
face=" & Chr(34) & "Verdana, Arial, Helvetica, sans-serif" & Chr(34) &
"> p.s.s. These additional bonuses/bribes are not available to the
public – only valuable members like you! <strong><a href=" &
Chr(34) & "http://www.powerquotesplus.net/renew_1.asp?mem_email=" &
mem_email & Chr(34) & ">Renew today</a></strong> and, at the least, you
can walk away with some tools you will not find anywhere else on the
net!</font></p>" & vbCrlf & ""
MailBody = MailBody & "<p><font size=" & Chr(34) & "2" & Chr(34) & "
face=" & Chr(34) & "Verdana, Arial, Helvetica, sans-serif" & Chr(34) &
"> p.s.s.s. Remember just one more week!</font></p>" & vbCrlf & ""
MailBody = MailBody & "<hr width=" & Chr(34) & "95%" & Chr(34) & "
size=" & Chr(34) & "1" & Chr(34) & ">" & vbCrlf & ""
MailBody = MailBody & "<p><font size=" & Chr(34) & "1" & Chr(34) & "
face=" & Chr(34) & "Verdana, Arial, Helvetica, sans-serif" & Chr(34) &
">If you would like your name removed from future <strong>Powerquotes
Plus</strong> mailings, please send an email to <strong><a href=" &
Chr(34) & "mailto:[email protected]?Subject=Remove from PQ+
Mailings" & Chr(34) & ">[email protected]</a></strong> with
your request.</font></p>" & vbCrlf & ""
MailBody = MailBody & "<p><font size=" & Chr(34) & "1" & Chr(34) & "
face=" & Chr(34) & "Verdana, Arial, Helvetica, sans-serif" & Chr(34) &
">You were sent this email because you are a member of
<strong>Powerquotes Plus</strong> using the following email: " &
mem_email & "</font></p>" & vbCrlf & ""
MailBody = MailBody & "<p align=" & Chr(34) & "center" & Chr(34) &
"><font size=" & Chr(34) & "1" & Chr(34) & " face=" & Chr(34) &
"Verdana, Arial, Helvetica, sans-serif" & Chr(34) & ">(Pay member
reminder email)</font></p>" & vbCrlf & ""
MailBody = MailBody & "</td>" & vbCrlf & ""
MailBody = MailBody & "</tr>" & vbCrlf & ""
MailBody = MailBody & "</table>" & vbCrlf & ""
MailBody = MailBody & "</body>" & vbCrlf & ""
MailBody = MailBody & "</html>"

Dim objMsg
Set objMsg = Server.CreateObject("CDONTS.NewMail")
objMsg.From = "(e-mail address removed)"
objMsg.To = mem_email
objMsg.Subject = "About Your Powerquotes Plus Membership"
objMsg.Body = MailBody
objMsg.BodyFormat = 0
objMsg.MailFormat = 0
objMsg.Send

Set objMsg = nothing

' update database

SQLstmt = "UPDATE tbl_pqplus_members SET "
SQLStmt = SQLstmt & "action_status='" & email_action & "'"
SQLStmt = SQLStmt & " WHERE mem_email='" & mem_email & "'"

Set RS = Conn.Execute(SQLStmt)

If err.number>0 then
response.write "VBScript Errors Occured:" & "<P>"
response.write "Error Number=" & err.number & "<P>"
response.write "Error Descr.=" & err.description & "<P>"
response.write "Help Context=" & err.helpcontext & "<P>"
response.write "Help Path=" & err.helppath & "<P>"
response.write "Native Error=" & err.nativeerror & "<P>"
response.write "Source=" & err.source & "<P>"
response.write "SQLState=" & err.sqlstate & "<P>"
end if
IF conn.errors.count> 0 then
response.write "Database Errors Occured" & "<P>"
response.write SQLstmt & "<P>"
for counter= 0 to conn.errors.count
response.write "Error #" & conn.errors(counter).number & "<P>"
response.write "Error desc. -> " & conn.errors(counter).description & "<P>"
next
else
end if

end if

'end reminder email

next

rs.close
set rs=nothing
Conn.Close
set conn=nothing

Response.Redirect ("subscribers.asp")

%>
 
P

Patrice

You likely forgot to clear the string that contains the HTML code for each
message...

Patrice
 
A

Aaron [SQL Server MVP]

Stop using CDONTS already. See http://www.aspfaq.com/2026
Stop using a DSN. See http://www.aspfaq.com/2126
If you're using SQL Server:
consider using mail from within SQL Server - http://www.aspfaq.com/2403
use stored procedures - http://www.aspfaq.com/2201

Just inside your FOR loop, place this:

MailBody = ""

Otherwise, on the second iteration, you're just adding more text to the
MailBody you had in the previous iteration.

I also recommend keeping this big block of code in an #include file so you
don't have to look at it when you're trying to develop/debug. I notice you
never use mem_email or mem_first within the body itself, but it would be
easy to incorporate. In the include file:

<%
mailbody = "Hello __firstname__, big long string here with a bunch of
useless HTML that will never be seen by most viewers..."
%>

And in your code:

For iLoop = 0 to iCount
mailbody = replace(mailbody, "__firstname__", mem_first)
Set objMsg = CreateObject("CDONTS.NewMail")
objMsg.From = "(e-mail address removed)"
objMsg.To = mem_email
objMsg.Subject = "About Your Powerquotes Plus Membership"
objMsg.Body = MailBody
objMsg.BodyFormat = 0
objMsg.MailFormat = 0
objMsg.Send
Set objMsg = nothing
Next

Isn't that much easier to look at?????

--
Please post DDL, sample data and desired results.
See http://www.aspfaq.com/5006 for info.
 
B

BaWork

Patrice said:
You likely forgot to clear the string that contains the HTML code for each
message...

Patrice


I tried that and it didn't work - maybe I did it wrong. What would be
the correct syntax?

Wouldn't it just be:

MailBody = ""

and I place it just above this piece of code:

Set objMsg = nothing

I didn't have to do that with the plain text version though....

Thanks

Brett
 
A

Aaron [SQL Server MVP]

You should put it at the top.

Plus, because of on error resume next, perhaps the line is being skipped,
who knows what's happening when you're creating and destroying that huge
object every time in your loop...
 
A

Adrienne

Stop using CDONTS already. See http://www.aspfaq.com/2026
Stop using a DSN. See http://www.aspfaq.com/2126
If you're using SQL Server:
consider using mail from within SQL Server -
http://www.aspfaq.com/2403 use stored procedures -
http://www.aspfaq.com/2201

Just inside your FOR loop, place this:

MailBody = ""

Otherwise, on the second iteration, you're just adding more text to the
MailBody you had in the previous iteration.

I also recommend keeping this big block of code in an #include file so
you don't have to look at it when you're trying to develop/debug. I
notice you never use mem_email or mem_first within the body itself, but
it would be easy to incorporate. In the include file:

<%
mailbody = "Hello __firstname__, big long string here with a bunch
of
useless HTML that will never be seen by most viewers..."
%>

And in your code:

For iLoop = 0 to iCount
mailbody = replace(mailbody, "__firstname__", mem_first)
Set objMsg = CreateObject("CDONTS.NewMail")
objMsg.From = "(e-mail address removed)"
objMsg.To = mem_email
objMsg.Subject = "About Your Powerquotes Plus Membership"
objMsg.Body = MailBody
objMsg.BodyFormat = 0
objMsg.MailFormat = 0
objMsg.Send
Set objMsg = nothing
Next

Isn't that much easier to look at?????

Additionally, remove all the presenational markup and use CSS, but put the
CSS in the head (some mail clients remove/ignore external stylesheets). It
would probably also do good to validate the HTML <http://validator.w3.org>
as you might have some unclosed tags.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top