Skip navigation
Currently Being Moderated

Email Notification

Nov 20, 2012 8:19 PM

(I first posted this on the dynamic dreamweaver forum but I think I was supposed to post my question here)

 

Hi,

 

I'm trying to figure out a way to notify someone that another person has replied to a post they made in a discussion.  I'm pretty sure I know how to figure out who the email should be sent to, but for now I'm just trying to get it to work by just sending it to my personal email.  This is the code I'm trying to get to work:

 

Thanks,

Mike

======================================================================

                  <cfif isDefined("FORM.title")>

 

  <cfprocessingdirective suppresswhitespace="No">

      <span class="blogtitle">Your Email has been sent.<br><br>I'll get back to you as soon as I can.

    </span>

  

  <cfmail

                    TO="mikewycklendt@gmail.com"

        from="""#FORM.username#"" <mikewycklendt@mymindsnotright.com>"

        subject="#FORM.title#"

        server="scriptmail.intermedia.net" 

        >This is a message from #FORM.username#:

Email: #FORM.username#

-------------------------------------------------

#FORM.content#

 

 

</cfmail>

  

    </cfprocessingdirective>

 

 

 

 

  <cfelse>

 

 

<form method="post" name="form1" action="<cfoutput>#CurrentPage#</cfoutput>">

                    <table align="center" cellpadding="4">

                      <tr valign="baseline">

                        <td colspan="2" align="left" nowrap bgcolor="#FFFFFF" class="blogtitle"> </td>

                        </tr>

                      <tr valign="baseline">

                        <td align="right" nowrap class="bloguserandwho"> </td>

                        <td><input type="hidden" name="user_id" value="<cfoutput>#rsGetUserID.user_id#</cfoutput>" size="32"></td>

                      </tr>

                      <tr valign="baseline">

                        <td align="right" nowrap class="bloguserandwho">Username:</td>

                        <td><input type="hidden" name="username" id="username" value="<cfoutput>#Session.MM_Username#</cfoutput>" size="32" />                          <cfoutput>#Session.MM_Username#</cfoutput>

                        

                        

                        

                        

                        

                          </td>

                      </tr>

                      <tr valign="baseline">

                        <td align="right" nowrap class="bloguserandwho">Title:</td>

                        <td><input type="text" name="title" id="title" value="" size="32"></td>

                      </tr>

                      <tr valign="baseline">

                        <td align="right" valign="top" nowrap class="bloguserandwho">Content:</td>

                        <td><textarea name="content"  id="content" cols="30" rows="5"></textarea></td>

                      </tr>

                      <tr valign="baseline">

                        <td nowrap align="right"> </td>

                        <td><input type="submit" value="Post Reply"></td>

                      </tr>

                    </table>

    <input type="hidden" name="reply_id" value="<cfoutput>#IncrementValue(rsReplyRecordCount.RecordCount)#</cf output>">

                    <input type="hidden" name="post_id" value="<cfoutput>#URL.post_id#</cfoutput>">

                    <input type="hidden" name="board_id" value="1">

                    <input type="hidden" name="date" value="<cfoutput>#now()#</cfoutput>">

                    <input type="hidden" name="MM_InsertRecord" value="form1">

                  </form>

                           </cfif>

 
Replies
  • Currently Being Moderated
    Nov 21, 2012 3:35 AM   in reply to wycks

    Could you tell us what the problem is.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 21, 2012 11:43 AM   in reply to wycks

    Comment out the rest of the code and run just this test code:

     

    Your Email has been sent.<br>

    I'll get back to you as soon as I can.<br>

    <cfmail

    to="mikewycklendt@gmail.com"

    from="mikewycklendt@mymindsnotright.com"

    subject="Test title"

    server="scriptmail.intermedia.net">

    E-mail message sent as test.

    </cfmail>

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 21, 2012 12:08 PM   in reply to wycks

    It is easier to test 2 lines of code than 5 miles of it. Notice that the test I suggested, by not using form variables, actually verifies whether they are the cause of the problem.

     

    In any case, one thing in particular caught my eye. The attribute

     

       from="""#FORM.username#"" <mikewycklendt@mymindsnotright.com>"

     

    What happens when you replace it with either

     

        from="mikewycklendt@mymindsnotright.com"

     

    or

     

        from="#FORM.username#"

     

    (I am assuming here that FORM.username is an e-mail address)

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 21, 2012 12:48 PM   in reply to wycks

    Repeating what BKBK said, step 1 is to run a mail tag in isolation to make sure that works.

     

    If the mail tag works, then start looking at your logic.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 21, 2012 11:56 PM   in reply to wycks

    wycks wrote:

     

    on the page i have where the cfmail does work, I have this to start the form:

     

      <cfform action="#cgi.SCRIPT_NAME#" method="post">

     

    on the page I'm currently working on, it says this:

     

    <form method="post" name="form1" action="<cfoutput>#CurrentPage#</cfoutput>">

     

    I see two differences--the different form actions and the fact that one is a cfform while the owther is a regular form.  Do eitehr of those two differences matter?

    That shouldn't matter. However, the dynamic variable, CurrentPage, is a possible source of error. How do you define it? In view of the fact that you wish to include the form, my guess is that you might have ignored the fact that functions like expandPath() and getCurrentTemplatePath() return the absolute path.

     

    Try something like this on the form page:

     

    <cfset rootPath = expandpath("/")>

    <cfset currentTemplateAbsolutePath = getCurrentTemplatePath()>

    <cfset currentTemplateRelativePath = replaceNoCase(currentTemplateAbsolutePath,rootPath,"")>

    <cfset currentTemplateRelativePath = "/" & replace(currentTemplateRelativePath,"\","/","all")>

     

     

    <cfoutput><form method="post" name="form1" action="#currentTemplateRelativePath#"></cfoutput>

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 24, 2012 1:00 AM   in reply to wycks

    wycks wrote:

     

    First, after I submit the form, a goes to a blank page that only says: "Your Email has been sent.  'll get back to you as soon as I can" instead of back to the topic on the forum.

    The code is behaving as it should. From what you described, the action page of the form (which is also where cfmail is processed) is the same as the page containing the form.

     

    Do you mean by 'the topic of the forum' the main page in which the form page is included? If so, and if you want the form to be posted to it, then delete the block

     

    <cfset rootPath = expandpath("/")>

    <cfset currentTemplateAbsolutePath = getCurrentTemplatePath()>

    <cfset currentTemplateRelativePath = replaceNoCase(currentTemplateAbsolutePath,rootPath,"")>

    <cfset currentTemplateRelativePath = "/" & replace(currentTemplateRelativePath,"\","/","all")>

     

    and use instead

     

    <cfoutput><form method="post" name="form1" action="#CGI.SCRIPT_NAME#"></cfoutput>

     

    Second, the form is not submitting so while I am getting email notification now, the form doesn't post the reply to the topic on the forum.

    The form is definitely submitting. The fact that you get e-mail means isDefined("FORM.title") is true, which in turn means the form is submitted. My question is, how would you draw any conclusion about the form variables without outputting any of them in the mail?

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 24, 2012 11:19 AM   in reply to wycks

    Simplify the code you've just given like this, and try again:

     

    <cfif isDefined("FORM.title")>

        <cfmail

            TO="mikewycklendt@gmail.com"

            from="mikewycklendt@mymindsnotright.com"

            subject="Subject"

            server="scriptmail.intermedia.net" 

            >

            This is a message from

            -------------------------------------------------

            Content

        </cfmail>

     

    <span class="blogtitle">Your Email has been sent.<br><br>I'll get back to you as soon as I can.</span>

     

    <cfelse>

     

        <cfform method="post" name="form1" action="#CGI.SCRIPT_NAME#">

        <table align="center" cellpadding="4">

        <tr valign="baseline">

        <td colspan="2" align="left" nowrap bgcolor="#FFFFFF" class="blogtitle"> </td>

        </tr>

        <tr valign="baseline">

        <td align="right" nowrap class="bloguserandwho"> </td>

        <td><cfinput type="hidden" name="user_id" value="#rsGetUserID.user_id#" size="32"></td>

        </tr>

        <tr valign="baseline">

        <td align="right" nowrap class="bloguserandwho">Username:</td>

        <td><cfinput type="hidden" name="username" id="username" value="#Session.MM_Username#" size="32" />                          <cfoutput>#Session.MM_Username#</cfoutput>

        </td>

        </tr>

        <tr valign="baseline">

        <td align="right" nowrap class="bloguserandwho">Title:</td>

        <td><cfinput type="text" name="title" id="title" size="32"></td>

        </tr>

        <tr valign="baseline">

        <td align="right" valign="top" nowrap class="bloguserandwho">Content:</td>

        <td><textarea name="content"  id="content" cols="30" rows="5"></textarea></td>

        </tr>

        <tr valign="baseline">

        <td nowrap align="right"> </td>

        <td><cfinput name="submit" type="submit" value="Post Reply"></td>

        </tr>

        </table>

        <cfinput type="hidden" name="reply_id" value="#IncrementValue(rsReplyRecordCount.RecordCount)#">

        <cfinput type="hidden" name="post_id" value="#URL.post_id#">

        <cfinput type="hidden" name="board_id" value="1">

        <cfinput type="hidden" name="date" value="#now()#">

        <cfinput type="hidden" name="MM_InsertRecord" value="form1">

        </cfform>

    </cfif>

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 24, 2012 11:55 AM   in reply to wycks

    Temporarily comment out the cfmail tag. Run in its place <cfdump var="#form#">. What do you get after submitting the form?

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 25, 2012 12:22 AM   in reply to wycks

    wycks wrote:

     

    I took out the cfmail tag and replaced it with the cfdump and nothing changes--obviously, i'm not getting an email, but the form is working properly as the reply does show up on the topic.  With the cfdump in place of the cfmail, the same exact thing happens with the cfmail tag and without the cfdump---i'm seeing nothing different.

    Just to be clear, is the form structure dumped or not?

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 25, 2012 12:56 AM   in reply to wycks

    I think I have found the cause of the problem. The code you gave above for the "larger page"(see 6. wycks) can be summarized as:

     

    ...

    something, something, something

    ...

    <cfif IsDefined("FORM.MM_InsertRecord") AND FORM.MM_InsertRecord EQ "form1">

        ...

    <cflocation url="discussionGenReplies.cfm?post_id=#FORM.post_id#">

        ...

    </cfif>

    ...

    <cfinclude template="discussionGenRepliesFORMinclude.cfm">

    ...

     

    When the form is submitted to this page, isDefined("FORM.MM_InsertRecord") AND FORM.MM_InsertRecord EQ "form1" becomes true. Coldfusion accordingly redirects execution to discussionGenReplies.cfm. There is therefore no opportunity to run the cfmail tag in discussionGenRepliesFORMinclude.cfm.

     

    Now, a possible solution. You might want to move the cfmail tag to this main page, before the cflocation tag. Or else include the form page before the cflocation tag.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 25, 2012 11:30 PM   in reply to wycks

    Glad to hear it's all working. Good luck with the rest.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points