I have used the cfmail tag alot but dont get the following to work. I have a form were a system administrator can submit a email to all subscribers informing them of 'something', whatever.
My problem is, the text area field is being used for the body of the mail being send via cfmail query
How do I transform the {NAME} inside the textare to the users real name when the cfmail page process the textarea content.
Dear {NAME}, welcome to our site. <-- This gets pass onto the cfmail page for processing?
You can string replace the {NAME} with the user's name (which I assume is on a form somewhere). For example:
<cfset mailBody = Replace(form.body, "{NAME}", form.name, "all") />
cmhampton
Junior Poster in Training
79 posts since Feb 2008
Reputation Points: 23
Solved Threads: 10
You need to cfloop through the query.
<cfquery name="rsSubscribersMail" datasource="DATA">
SELECT subscriber.subscriberID, subscriber.name, subscriber.surname, subscriber.email
FROM subscriber
</cfquery>
<cfloop query="rsSubscribersMail">
<cfset mailBody = Replace(#form.body#, "{NAME}", #rsSubscribersMail.name#, "all") />
<cfmail to="#rsSubscribersMail.email#" from="#form.from#" subject="#form.subject#" server="127.0.0.1" port="25">
#mailBody#
</cfmail>
</cfloop>
If you don't loop through the query, it will always use the values from the first record.
cmhampton
Junior Poster in Training
79 posts since Feb 2008
Reputation Points: 23
Solved Threads: 10
Is it possible to 'replace' more than one, {Name} {SURNAME}
You can use a second Replace function:
<cfset mailBody = Replace(#form.body#, "{NAME}", #rsSubscribersMail.name#, "all") />
<cfset mailBody = Replace(#mailbody#, "{SURNAME}", #rsSubscribersMail.surname#, "all") />
cmhampton
Junior Poster in Training
79 posts since Feb 2008
Reputation Points: 23
Solved Threads: 10