Skip to main content
Inspiring
April 14, 2008
Question

cfmail help

  • April 14, 2008
  • 4 replies
  • 291 views
I have the following query that will give me email address and I put into cfmail. I am passing a value (in this case 7) into the form.site varaible. For my test sample, there are 8 records but for some reason, I am only getting one name. I have two queries, one dyanamically and one hardcoded, and the hardcode one seems to give me everyone but the other one only gives me one name. Both queries are/sould be the same.

I cannot see what the problem is, can somebody please help ?


<cfif isDefined("form.site")>
<cfoutput>form.site is #form.site#<br></cfoutput>

dynamic starts here

<cfquery name="qryGet_roles" datasource="recDisc">
select
user_employee_number,
user_name,
user_email,
user_status,
role_id
from tblUnReceivables_User_Directory
where role_id in ('#form.site#')
and (user_status = 'Active')
order by role_id, user_name
</cfquery>


<cfoutput query="qryGet_Roles">#user_email#<br></cfoutput>


hardcoded starts here

<cfquery name="qryGet_roles_1" datasource="recDisc">
select
user_employee_number,
user_name,
user_email,
user_status,
role_id
from tblUnReceivables_User_Directory
where role_id in ('7')
and (user_status = 'Active')
order by role_id, user_name
</cfquery>

<cfoutput query="qryGet_Roles_1">#user_email#<br><cfabort></cfoutput>

<cfmail to="#qryGet_Roles.user_email#"
cc="#form.additional_email#"
from="UnReceivables Team"
subject="URDN #form.urdn_number#"
query="qryGet_Roles"
type="html">
    This topic has been closed for replies.

    4 replies

    Inspiring
    April 16, 2008
    when you use QUERY attribute in cfmail tag, the tag acts akin to
    CFOUTPUT tag. thus cfmail will run as many times as there are records in
    the query resultset. and all of your multiple addresses in the TO
    attribute will be sent an email as many times.

    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/
    trojnfnAuthor
    Inspiring
    April 16, 2008
    Can somebody tell me what is wrong with my code. I query email addresses and put into cfmail. All works fine except that if there are 5 records, it generates five emails to each person, instead of one email. I cannot figure it out.

    <cfif isDefined("form.site")>


    <cfquery name="qryGet_roles" datasource="recDisc">
    select
    user_employee_number,
    user_name,
    user_email,
    user_status,
    role_id
    from tblUnReceivables_User_Directory
    where role_id in ('#form.site#')
    and (user_status = 'Active')
    order by role_id, user_name
    </cfquery>



    <cfmail to="#valuelist(qryGet_Roles.user_email,',')#"
    cc="#form.additional_email#"
    from="xxxx"
    subject=" #form.number#"
    query="qryGet_Roles"
    type="html">


    </cfif>
    trojnfnAuthor
    Inspiring
    April 15, 2008
    For some unkown reason, the queries are working now, displaying the same values in the dynamic and hardcoded.

    Anyway, my variable form.site that I pass, are checkboxes and the values come across as 1,3,7 (if checkboxes 1, 3, and 7 were selected on the form). I then insert this into my query and use 'where role_id in ('#form.site#')', which is 'where role_id in ('1','3','7'), to find the email address.

    Now I have two questions :
    1. If I find matches for all 3 values, will it give me all three emails addresses and send the email to this person three times ? If yes, how do I send one email only, per email address, regardless of how many matches are found ?

    2. I put myself on cc (copy) to get the emails also. What appears to be happening is that if 5 emails are sent to five different people, I get five emails because I am on copy. I should only be getting one email. What do I need to do ?
    Inspiring
    April 15, 2008
    Your problem might be trailing spaces. Why is role_id a character field instead of numeric?

    Or, more likely, it could be the position of your cfabort tag.