2 Replies Latest reply on Sep 28, 2010 12:50 PM by Reed Powell

    ColdFusion Mail Merge?

    WestSide Level 1


      I am building a dynamic email and i wanted to see has anyone created a mail merge type email with ColdFusion?  I wanted the user to be able to have a set of fields to choose and type them into the body of the message.  When the email goes out, the fields like << First_Name >> or something like that would be replaced with the actual values from the db.

      Any insight on how I could do this would be great!





        • 1. Re: ColdFusion Mail Merge?
          ilssac Level 5

          WestSide wrote:


          Any insight on how I could do this would be great!


          With the <cfmail....> tag.  The documentation has all the details.  But to give you a preview, a <cfmail...></cfmail> block has the same property as an <cfoutput...></cfoutput> in that it will render any variables contained inside for their values.  Thus variables like #firstName# would be rendered into what ever value that variable contained.

          • 2. Re: ColdFusion Mail Merge?
            Reed Powell Level 3

            Piece of cake.  I do this sort of thing for neighborhood email blasts using a table that has everyone's name, email, etc., in it. Just use the rich text editor in a cfform to let the person compose the message - that gives them fonts, colors, etc., for formatting a nice message.  Come up with a simple meta syntax for how they type in the items that get replaced in the actual email with database items, just like you did in your example.   I wouldn't go the route of having the user type in using the #xxx# syntax because then you have to deal with possible errors when they spell things wrong, leave out a #, etc. Plus, the Rich text editor is going to mess with the # signs anyway.  Just come up with something like <firstname> or [firstname], etc.  Make it easy for the user by listing somewhere on the form page each of the possible things they can include - that way they can copy/paste if they want to.


            On the form processing page you just loop over the database resultset and use replaceNoCase() to replace each of those metas with the current row's database value, and then drop that modified variable into the cfmail tag:

                 <cfmail from="ME" to="#queryname.you#" type="HTML">




            If you're talking about sending a lot of emails you should check postings from about 4-6 weeks ago on the topic of using CF for mass mailings, and avoiding problems with your ISP that get you in hot water because they think you are a spam-bot.