Link to home
Start Free TrialLog in
Avatar of JohnMac328
JohnMac328Flag for United States of America

asked on

CF - Send cfmail with email address from session ID

I have a form that sends a thank you note.  It works fine except the from field should have the email of the person that is submitting the form.  I have tried several things but the closest I get is the session.ID appearing in the from field.  I also tried a query within a query but it does not understand what the field is I am referring to.  It is bombing on line 39 in the code window

Variable FROMEMAIL is undefined.  
 
 
The error occurred in C:\inetpub\wwwroot\maxibillion_CF\send_thankyou.cfm: line 55
 
53 : <CFMAIL query="SendResults"
54 :             to="#trim(Toemail)#@company.com "
55 :             from="#trim(Fromemail)#@company.com "

 


Any help is appreciated

<cfparam name="form.employeeID" default="#SESSION.ID#">

<cfif not IsDefined('SESSION.ID')>
  <cflocation url="login.cfm">
</cfif>

<cfquery name="getMembers" datasource="IntranetDB_Coldfusion">
SELECT    ID, last_name, first_name, email_name
FROM  employee_data
ORDER BY last_name, first_name
</cfquery>

<cfif structKeyExists(FORM, "submitButton")>

 <cfquery name="Get_To" datasource="IntranetDB_Coldfusion">
SELECT     ID, last_name as ToLast_name, first_name as ToFirst_name, email_name as Toemail
FROM         employee_data
WHERE     (ID = #form.SendThanks#)
  </cfquery>
  
   <cfquery name="Get_From" datasource="IntranetDB_Coldfusion">
SELECT     ID, last_name as FromLastname, first_name as FromFirstname, email_name as Fromemail
FROM         employee_data
WHERE  employee_data.ID = '#SESSION.ID#'
  </cfquery>
    <cfquery name="SendResults" dbtype="query">
SELECT Distinct
Get_To.*
FROM
Get_To,
GET_From
WHERE
GET_To.ID IN (GET_From.ID)
  </cfquery> 
   <cfdump var="#form#">
  
<CFMAIL query="SendResults"
            to="#trim(Toemail)#@usfunds.com"
            from="#trim(Fromemail)#@usfunds.com"
            spoolenable="no"
            type="html"
            Subject="Test Results - thanks">
  <table border="0" cellpadding="0" cellspacing="0" style="width:100%; font-family:Arial, Helvetica, sans-serif;">
    <tr>
      <td><p>Dear #SendResults.ToFirst_name#&nbsp;#SendResults.Tolast_name#,
        <p><p>I just wanted to say "#form.reason#".
        <p>Sincerely,
        <p>#SendResults.Fromfirst_name#&nbsp;#SendResults.FromLastname#
        </td>
    </tr>
  </table>
</CFMAIL> 
</cfif>
<body class="twoColElsLtHdr">
<div id="container">
<div id="header"> <img src="images/USGI_Masthead.gif" />
  <div id="mainContent">
    <table class="displayTable">
      <cfform action="send_thankyou.cfm" method="POST" preloader="no">
      <cfinput type="hidden" name="employeeID" value="#employeeID#">

        <tr>
        <tr>
          <th>Send a Thank You</th>
        </tr>
        <tr>
          <td><img src="images/thankyou.gif" width="234" height="144"></td>
          <td>Send To:<br>
            <cfselect name="SendThanks"> <cfoutput query="getMembers">
              <option value="#ID#"> #last_name# ,#first_name#</option>
            </cfoutput> </cfselect>
            <br>
            <br>
            Thank you note:<br>
            <br>
            <cftextarea name="Reason"></cftextarea></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><input type="submit" name="submitButton"  value="Submit"></td>
        </tr>
      </cfform>
    </table>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of SidFishes
SidFishes
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think it's a variable scoping problem..  you really should always scope your variables.  With all those queries, you don't know which one you are getting the values of your variables from unless you specifically state it by using the scope.

In the below, I have guessed that you want to get the email names from the GET_FROM query...

Scoping variables helps a lot with debugging too, that way developers don't have to guess where values come from :)

 <cfquery name="Get_From" datasource="IntranetDB_Coldfusion">
   SELECT     ID, last_name as FromLastname, first_name as FromFirstname, email_name as Fromemail
    FROM         employee_data
   WHERE  employee_data.ID = '#SESSION.ID#'
 </cfquery>
  
<cfif get_from.recordCount eq 0>No GET_FROM Found <cfexit></cfif>  

  <cfquery name="SendResults" dbtype="query">
    SELECT Distinct Get_To.*
    FROM Get_To, GET_From WHERE GET_To.ID IN (GET_From.ID)
  </cfquery> 
  <cfdump var="#form#">

<cfif SendResults.recordCount eq 0>No SENDRESULTS Found <cfexit></cfif>  

<CFMAIL query="SendResults"
            to="#trim(Get_From.Toemail)#@company.com "
            from="#trim(Get_From.Fromemail)#@company.com "
            spoolenable="no"
            type="html"
            Subject="Test Results - thanks">

Open in new window




Curious what the purpose of this is...

  <cfquery name="SendResults" dbtype="query">
    SELECT Distinct Get_To.*
    FROM Get_To, GET_From WHERE GET_To.ID IN (GET_From.ID)
  </cfquery>
  <cfdump var="#form#">

Does not seem necessary, and I don't believe it will work as you intend  as the GET_FROM.ID is only ONE value so should not be "IN ()"
Avatar of JohnMac328

ASKER

Looks like I was making it too complicated - thanks for the info!