Skip to main content
Known Participant
May 8, 2009
Answered

Cfmail processing error - what's wrong with my code?

  • May 8, 2009
  • 4 replies
  • 5681 views

Hi Everybody,

I am not a tech person but I'll try my best describing the situation.

When I yesterday tried to fix an error message (which always showed when not all requiered fields were filled in at our company's "Request for Quote" site), I think I messed up the whole inquiry-forwarding system. I must have deleted everything.

My company's using Macromedia Dreamwaver 8, and the guy who wrote the pages are long gone. If only I could revert the present non-functioning system how it used to be but it's too late, I already turned my comp off yesterday.

The way it should work is that the customer types in all info we need from him, then pushes the submit button, which then sends an email to us and leads the customer to our "Thank you for your inquiry" page. If some eror happens, it brings the customer to our mailto.cfm page, which now shows some error message I do not understand about the 3rd line, 

variable.fieldnames = ListDeleteAt(variable.fieldnames, ListFindNoCase(variable.fieldnames,"RECIPIENT") );

Here's what I found as an old-timer back-up to our mailto.cfm page (which I altered yesterday, and that caused the whole problem), which no longer works either:

<cfscript>
    variable.fieldnames = form.fieldnames;
    variable.fieldnames = ListDeleteAt(variable.fieldnames, ListFindNoCase(variable.fieldnames,"RECIPIENT") );
    variable.fieldnames = ListDeleteAt(variable.fieldnames, ListFindNoCase(variable.fieldnames,"SUBJECT") );
    variable.fieldnames = ListDeleteAt(variable.fieldnames, ListFindNoCase(variable.fieldnames,"THANKURL") );
</cfscript>
<cfparam name="FORM.SUBJECT" default="Web Site Form">
<cfmail to="ouremail@ourdomain.com" from="inforequest@ourdomain.com" subject="#FORM.SUBJECT#">#FORM.SUBJECT#
Sent #DateFormat(now(),'dddd mmmm d, yyyy')# @ #TimeFormat(now(),'h:mm tt')#

<cfloop index="i" list="#variable.fieldnames#"><cfif len(evaluate("form.#i#"))><cfif uCase(right(i,6)) eq "_BREAK">#chr(13)#</cfif>#ReplaceNoCase(i,"_BREAK","")#:#RepeatString(" ", evaluate(15-len(ReplaceNoCase(i,"_BREAK",""))))# #Replace( evaluate("form.#i#"), chr(10), chr(10) & RepeatString(" ",17), "All" )# #chr(13)#</cfif></cfloop>
</cfmail>

<cflocation url="#form.THANKURL#" addtoken="No">

It seems simple, the to-field is correct, the from-field must be too, why do you still think that it's not forwarding the inquiries as emails any more? Where is this code broken?

I would welcome all suggestions, I really need your help!

    This topic has been closed for replies.
    Correct answer ilssac

    It's much better now, the things that belong together stick close to each other now.

    I need to go just one step further, so they are not in one continuous line but below each other (starting with the title below the sending date, then below that firstname, below that last name etc...)

    Quote Request

    Sent Wednesday May 13, 2009 @ 9:37 AM                TITLE:Mr.            FIRSTNAME:TEST             LASTNAME:test               TITLE2:title              COMPANY:company                 CITY:city                STATE:state                  ZIP:12345                EMAIL:test@test.com     COMPRESSORMAKE_1:make    COMPRESSORMODEL_1:model         PARTNUMBER_1:part number


    Ok this is wierd, but your system does not seem to be accepting the line returns in the code.  That is not normal behavior.  But you can hard code them in.

    Out of curisoity what type of systems are you working with?

    <cfmail
       to="julianna@airengineering.com"
       from="#form.email#"
       subject="#FORM.SUBJECT#">

    #FORM.SUBJECT#

    Sent #DateFormat(now(),'dddd mmmm d, yyyy')# @ #TimeFormat(now(),'h:mm tt')##chr(13)##chr(10)#

    <cfloop list="#form.fieldnames#" index="field">
    <cfif listFindNoCase("RECIPIENT,SUBJECT,THANKURL",field) EQ 0><cfif len(trim(form[field])) GT 0>#repeatString(" ",20-len(replaceNoCase(field,"_BREAK","")))#
    #replaceNoCase(field,"_BREAK","")#:#replace(form[field],chr(10),chr(10 ) & repeatString(" ",17),"ALL")##chr(13)##chr(10)#
    </cfif></cfif>
    </cfloop>
    </cfmail>

    <cflocation url="#form.THANKURL#" addtoken="No">

    4 replies

    ilssac
    Inspiring
    May 12, 2009
    <cfmail

    to="julianna@airengineering.com"from="#form.email#"subject="#FORM.SUBJECT#">#FO RM.SUBJECT#

    Sent #DateFormat(now(),'dddd mmmm d, yyyy')# @ #TimeFormat(now(),'h:mm tt')#

    <cfloop list="#form.fieldnames#" index="field"><cfif listFindNoCase("RECIPIENT,SUBJECT,THANKURL",field) EQ 0><cfif len(trim(form[field])) GT 0>   #replaceNoCase(field,"_BREAK","")#:#repeatString(" ",20-len(replaceNoCase(field,"_BREAK","")))##replace(form[field],chr(10),chr(10) & repeatString(" ",17),"ALL")#<cfif uCase(right(field,6)) EQ "_BREAK">#chr(13)#</cfif></cfif>
    </cfif></cfloop>

    </cfmail>

    <cflocation url="#form.THANKURL#" addtoken="No">

    What does this output?

    Known Participant
    May 12, 2009

    Quote Request

    Sent Tuesday May 12, 2009 @ 5:52 PM TITLE:               Mr. FIRSTNAME:           test LASTNAME:            rt TITLE2:              df COMPANY:             adf ADDRESS1:            test CITY:                test ZIP:                 123456 PHONE:               TEST PHONE EMAIL:               blabla@blabla.com

    No breaks now at all!

    ilssac
    Inspiring
    May 12, 2009

    Do you have any of your form fields ending in "_BREAK"?

    This logic was apparently built contigent on certain fields would be named ending in "_BREAK" so that this code knew where to break the display.

    That is what this part of the code is trying to do.

    <cfif uCase(right(field,6)) EQ "_BREAK">#chr(13)#</cfif>
    ilssac
    Inspiring
    May 12, 2009

    New thread to eliminte the indenting again.

    Paste your code then select it and the find the "Syntax Highlighting > Plain" function in the above menu that is two blue >> brackets on my screen.

    It will produce a display that looks like this.

    Alternative you can inclose the text in<pre class="jive_text_macro jive_macro_code" jivemacro="code" ___default_attr="plain"></pre> tags in the plain text input control... click the "HTML" link to get that.

    ilssac
    Inspiring
    May 11, 2009

    Starting a New reply thread as the old one was getting two narrow to read.

    Julianna01 wrote:

    Hi Ian,

    I changed the middle "15" to "20", not even really knowing what it meant because an error message did not like the 15 for some reason.

    The number, as the comment indicates is to add spaces to the beginning of form field names to make them all the same lenght.  If the field name is longer then the provided lenght, then the 15-lenght would return a negative number which is illegal in for a repateString() function.

       <!--- Loop over all the fields of the form collection --->
       <cfloop collection="#form#" item="field">

    Change this to a list loop that will loop over the form fields in the same order they are in the form.fieldnames variable.  This is what the original code did.  It relies on the the order of the field as provided by the browser and the web server, which apparently is the order they are in the form page.  I am not sure I would rely on this order, but it is what the original coder did.

    <!--- Loop over all the field in the form.fieldnames list --->

    <cfloop list="#form.fieldnames#" index="field">

    The the last part of the orginal code was logic to remove some field names so they did not get printed... Here is a little easier way to do that piece.

    <!--- Loop over all the field in the form.fieldnames list --->

    <cfloop list="#form.fieldnames#" index="field">

      <!--- Skip these field names --->

      <cfif listFindNoCase("RECIPIENT,SUBJECT,THANKURL",field) EQ 0>

      <!--- NOTE: PUT the exact field name of any form field not to include in the above list --->

      <!--- NOTE: If listFindNoCase() returns 0, then this field is not in the list so process it --->

         ... rest of the code ...

      </cfif>

    </cfloop>

    Known Participant
    May 11, 2009

    Hi Ian,

    We're getting there, thx for getting back to me, hope you had a great weekend:-))!

    I am so not sure what caused now what, but it definately is way better now! The "form. fieldnames" repaired the order (made it just like online, and that's what I need), and after I added a finishing  </cfif>, your other few lines work now too.

    This is how it looks right now:

    ....the starting few lines...

    <!--- Loop over all the field in the form.fieldnames list --->
    <cfloop list="#form.fieldnames#" index="field">

      <!--- Skip these field names --->
      <cfif listFindNoCase("RECIPIENT,SUBJECT,THANKURL",field) EQ 0>
      <!--- NOTE: PUT the exact field name of any form field not to include in the above list --->
      <!--- NOTE: If listFindNoCase() returns 0, then this field is not in the list so process it --->
      </cfif>

         <!--- If the current form field contains a non-empty string --->
         <cfif len(trim(form[field])) GT 0>
          #replaceNoCase(field,"_BREAK","")#:                                 <!--- output the field name without the string '_BREAK'--->
          #repeatString(" ",20-len(replaceNoCase(field,"_BREAK","")))#        <!--- Space pad the form field to 20 characters --->
          #replace(form[field],chr(10),chr(10) & repeatString(" ",17),"ALL")# <!--- Replace all new line chr(10) characters with a new line and 17 spaces --->
          <cfif uCase(right(field,6)) EQ "_BREAK">#chr(13)#</cfif>            <!--- if the field name contains the string '_BREAK' output a carriage return chr(13) character --->
         </cfif>
       </cfloop>
    </cfmail>

    <cflocation url="#form.THANKURL#" addtoken="No">

    and that's how the TEST emails come back:

    Quote Request

    Sent Monday May 11, 2009 @ 2:46 PM SUBJECT:                                

                       Quote Request THANKURL:                                

                      thankyou.htm TITLE:                                

                         Mr. FIRSTNAME:                                

                     TESTfirst LASTNAME:                                

                      TESTlast TITLE2:                                

                        TESTtitle COMPANY:                                

                       TESTcompany ADDRESS1:                                

                      TESTadd CITY:                                

                          TESTcity STATE:                                

                         teststate ZIP:                                

                           12345test PHONE:                                

                         12345678test EMAIL:                                

                         TESTemail@test.com COMPRESSORMAKE_1:                                

              TESTmake

    COMPRESSORMODEL_1:                                

             TESTmodel COMPRESSORSERIAL_1:                                

            TESTserial COMPRESSORMAKE_2:                                

              TESTmake2

    QUANTITY_1:                                

                    1test

    PARTNUMBER_1:                                

                  TESTpart DESCRIPTION_1:                                

                 TESTdesc. COMMENTS:                                

                      TEST Comment

    I have a few questions:

    1. How can I put the field names and the field inputs to the same row?

    2. How can I make them start from the same place vertically so the email is nicely structured?

    3. And it's getting tricky here: how can I make the email's sender to show the email address who made the inquiry? (..and not how it is right now: all emails come from one of our email addresses and the sender's email address only shows in the email's body)

    ilssac
    Inspiring
    May 11, 2009

    Julianna01 wrote:

    I have a few questions:

    1. How can I put the field names and the field inputs to the same row?

    2. How can I make them start from the same place vertically so the email is nicely structured

    These spacing issues are from the spacing of the code.  For text emails (the default) all whitespace between the opening <cfmail...> and the closing </cfmail> tags count.  I put a lot of extra spaces and returns in my code examples to make it easier for you to read, and they are showing up in the messages.  You just need to adjust the code to eliminate the undesired whitespace.  It will make the code hard to read, but the emails nicer.

    3. And it's getting tricky here: how can I make the email's sender to show the email address who made the inquiry? (..and not how it is right now: all emails come from one of our email addresses and the sender's email address only shows in the email's body)


    Put the #form.email# (or whichever form field contains the desired email data) into the <cfmail ... from="#form.email#" ...> parameter.

    ilssac
    Inspiring
    May 8, 2009

    I don't even know where to start with that code... It must not be copied correctly in this forum.  I don't see closing tags, quotes all kinds of syntax that would all this to be return anything but garbage.

    What is the error message you are receiving?

    What exactly is gone? What is be restored?

    You are describing a pretty simple requirement that should not take a person very long to recreate if there is not more to the details.

    A basic contact HTML Form and a CFML action page to email  it somewhere is ColdFusion 101 and can be found in most basic CF turtorials and books.

    Here is the section of the ColdFusion documentation that includes example code.

    http://livedocs.adobe.com/coldfusion/8/htmldocs/email_04.html

    Known Participant
    May 8, 2009

    I am soo confused too. First of all, I do not understand how could I have changed the well-functioning of the whole email sending process when I only edited the strange error message page (which is called mailto.cfm)...Until this morning I did not even had an idea what is Coldfusion.

    Anyways, on our quote request page there's plenty of info to be entered and we need an email about all those, like date, name, title, company name etc, everything that was entered there for that query. I do not even know if what version of Coldfusion should I use, or at all, if I should use Coldfusion, then how should this code look like, and all in all, why cannot life be easier?:-))

    After the quote request page, this comes up immediately, instead of the thank you page. The error message right now says:

    Error Occurred While Processing Request

    Invalid list index 0.

    In function ListDeleteAt(list, index [, delimiters]), the value of index, 0, is not a valid as the first argument (this list has 30 elements). Valid indexes are in the range 1 through the number of elements in the list.
    The error occurred in E:\inetpub\users\ourdomain.com\www\mailto.cfm: line 3
    1 : <cfscript>
    2 :      variable.fieldnames = form.fieldnames;
    3 :      variable.fieldnames = ListDeleteAt(variable.fieldnames, ListFindNoCase(variable.fieldnames,"RECIPIENT") );
    4 :      variable.fieldnames = ListDeleteAt(variable.fieldnames, ListFindNoCase(variable.fieldnames,"SUBJECT") );
    5 :      variable.fieldnames = ListDeleteAt(variable.fieldnames, ListFindNoCase(variable.fieldnames,"THANKURL") );

    Please try the following:

    Browser  Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10
    Remote Address  our IP
    Referrer  http://ourdomain.com/contact.htm
    Date/Time  08-May-09 02:21 PM
    Stack Trace
    at cfmailto2ecfm356598027.runPage(E:\inetpub\users\ourdomain.com\www\mailto.cfm:3)                 

    coldfusion.runtime.InvalidListIndexException: Invalid list index 0.
         at coldfusion.runtime.ListFunc.ListDeleteAt(ListFunc.java:146)
         at coldfusion.runtime.CFPage.ListDeleteAt(CFPage.java:2391)
         at cfmailto2ecfm356598027.runPage(E:\inetpub\users\ourdomain.com\www\mailto.cfm:3)
         at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:147)
         at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:357)
         at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:62)
         at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:107)
         at coldfusion.filter.PathFilter.invoke(PathFilter.java:80)
         at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:47)
         at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
         at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:35)
         at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:43)
         at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
         at coldfusion.CfmServlet.service(CfmServlet.java:105)
         at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:91)
         at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
         at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:252)
         at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:527)
         at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:192)
         at jrunx.scheduler.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:348)
         at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:451)
         at jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable(ThreadPool.java:294)
         at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)
    ilssac
    Inspiring
    May 8, 2009

    Ok, now I have some place to start to help.

    First of all you do not need to know about what version of ColdFusion to use.  ColdFusion is the language, not the Integrated Development Environment.  All that Code you see that looks like <cfthis...> and <cfthat> that is the CFML i.e. ColdFusion Markup Language your application was written in.

    mailto.cfm is a CFML file that is processing your contact form when it is submitted.  It is building the email to be sent.  It is not the error message page, it is a page throwing an error.

    The error it is thowing is "Invalid list index 0".   It thinks the error is on line 3, CF is pretty good at getting the right line for an error, but sometimes you need to look around that line for the true cause of the error.

    In your case line 3 is: "variable.fieldnames = ListDeleteAt(variable.fieldnames, ListFindNoCase(variable.fieldnames,"RECIPIENT") );" and I think it is likely the source of the error.  This line wants to delete an item from the list 'variables.fieldnames'.  The item it wants to delete is whereever an item equal to 'RECIPENT' is in the 'variables.fieldnames' list.  The problem is that 'RECIPENT' is not an item in the variables.fieldnames list so the ListFindNoCase() function is returning the value 0 and the ListDeleteAt() function can not delete item 0 as that is illeagal so it is throwing an error.

    Why variable.fieldnames no longer has a value equal to 'RECIPENT' would depend on what changes you made to the code yesterday or today.