Solved

simple query question for big points!!

Posted on 2006-10-24
4
182 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

806 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