Solved

simple query question for big points!!

Posted on 2006-10-24
4
164 Views
Last Modified: 2013-12-24
Hello,

I am trying to set up a newsletter program for a client
but am having trouble getting the program to insert the
subscribers first name and email into the mailto script.

Here is the query I am using and the code I am using to
try and send the emails.

<cfquery name="send" datasource="#dsn#" username="#user#" password="#pass#">
SELECT fName, email
FROM NEWSLETTER
WHERE active = '1'
</cfquery>

<cfmail to="#send.email#" from="newsletter@oldfarmkennels.com" subject="#send.fName#, #subject#">
Dear #send.fName#,

#copy#
***********************************************************
If you are receiving this in error or no longer wish to
receive this newsletter simply click on the link below to
be removed from any future mailings.

http://www.oldfarmkennels.com/ezine/unsubscribe.cfm
</cfmail>

<cflocation url="../ezine/success.cfm" addtoken="yes">

Thanks in advance for your help.

Sincerely,
Brandon
0
Comment
Question by:brandonpowell
4 Comments
 
LVL 12

Accepted Solution

by:
mkishline earned 500 total points
ID: 17799541
There are two ways you can do this:
1) Wrap your cfmail in a cfoutput:

<cfoutput query="send">
  <cfmail to="#send.email#" from="newsletter@oldfarmkennels.com" subject="#send.fName#, #subject#">
    ...
  </cfmail>
</cfoutput>

2) Use the query attribute of the cfmail tag:

<cfmail to="#send.email#" from="newsletter@oldfarmkennels.com" subject="#send.fName#, #subject#" query="send">
  ...
</cfmail>

Pick whichever one works cleanest for you.
0
 
LVL 36

Expert Comment

by:SidFishes
ID: 17799554
doesn't appear that there's anything wrong with the code..except it will only give you one record... are you getting an error?


you want to either use cfloop or cfoutput to output all

<cfquery name="send" datasource="#dsn#" username="#user#" password="#pass#">
SELECT fName, email
FROM NEWSLETTER
WHERE active = '1'
</cfquery>


<cfloop query="send">
<cfmail to="#send.email#" from="newsletter@oldfarmkennels.com" subject="#send.fName#, #subject#">
Dear #send.fName#,

#copy#
***********************************************************
If you are receiving this in error or no longer wish to
receive this newsletter simply click on the link below to
be removed from any future mailings.

http://www.oldfarmkennels.com/ezine/unsubscribe.cfm
</cfmail>
</cfloop>


or

<cfquery name="send" datasource="#dsn#" username="#user#" password="#pass#">
SELECT fName, email
FROM NEWSLETTER
WHERE active = '1'
</cfquery>

<cfoutput query="send">
<cfmail to="#send.email#" from="newsletter@oldfarmkennels.com" subject="#send.fName#, #subject#">
Dear #send.fName#,

#copy#
***********************************************************
If you are receiving this in error or no longer wish to
receive this newsletter simply click on the link below to
be removed from any future mailings.

http://www.oldfarmkennels.com/ezine/unsubscribe.cfm
</cfmail>
</cfoutput>


0
 
LVL 5

Expert Comment

by:rucky544
ID: 17819663
Do you mean

WHERE active = 1 <!--- this is if active is true, where as '1' would mean where active = 1 (as a string) --->

I don't know if your problem is that simple?
0
 
LVL 1

Expert Comment

by:ctdigital
ID: 17839868
<cfquery name="send" datasource="#dsn#" username="#user#" password="#pass#">
SELECT fName, email
FROM NEWSLETTER
WHERE active = 1
</cfquery>

<cfmail to="#send.email#" from="newsletter@oldfarmkennels.com" subject="#send.fName#, #subject#">
Dear #send.fName#,

#copy#

If you are receiving this in error or no longer wish to
receive this newsletter simply click on the link below to
be removed from any future mailings.

http://www.oldfarmkennels.com/ezine/unsubscribe.cfm
</cfmail>

<script>
      self.location="../ezine/success.cfm";
</script>


See if using javascript helps instead of using <cflocation> - Maybe I'm foolish but I remember having a similar issue to yours when I first started out in coldfusion.  Try using <script> self.location instead of <cflocation>
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now