Solved

simple query question for big points!!

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
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…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

733 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