Solved

simple query question for big points!!

Posted on 2006-10-24
4
205 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

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…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

707 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