Action Email - Dynamic To with Data db

federcla 13 Sep, 2013
Hi,
I would like to setting the Dynamic To with the data of my db

is it possible?

i have written this code for get the data


<?php

  $db =& JFactory::getDBO();
    
  $query_user = "SELECT a.email FROM sks_users AS a, sks_user_usergroup_map AS b, sks_usergroups AS c WHERE a.id = b.user_id AND b.group_id = c.id AND c.title = 'Prova Invio Email' AND a.block =0";
  $db->setQuery($query_user);
  $form->data['utenti'] = $db->loadAssocList();  
  
?>


after i have inert utenti in Dynamic To, but don't work

can you help me?

thanks
GreyHead 13 Sep, 2013
Hi federcla,

The query you have there will return an array of results not just a single email address. Add a Debugger action to see exactly what you are getting.

Bob
federcla 13 Sep, 2013
yes, I know it's an array, I need to load the addresses of the users of a particular group


Array
(
    [Itemid] => 184
    [option] => com_chronoforms
    [view] => form
    [utenti] => Array
        (
            [0] => Array
                (
                    [email] => prova1@gmail.com
                )

            [1] => Array
                (
                    [email] => prova2@gmail.com
                )

            [2] => Array
                (
                    [email] => prova3@gmail.com
                )

        )

)
GreyHead 16 Sep, 2013
Hi federcla,

Hmmm . . . that's an array of arrays . . .

You can convert it to a plain array with a Custom Code action.
<?php
$form->data['dyn_emails'] = array();
foreach ( $form->data['utenti'] as $v ) {
  $form->data['dyn_emails'][] = $v['email'];
}
?>

Then you can use my Email [GH] action* and put {dyn_emails} in the To Email box.

Bob

* The standard Email action won't accept an array or list of emails.
federcla 16 Sep, 2013
ok, now it is in a single array, but does not send the email, a message appears that says:

You must provide at least one receiver's email address
GreyHead 16 Sep, 2013
Hi federcla,

Please drag a Debugger action into the On Submit event, then submit the form and post the debug - including the 'dummy emails' results here.

Bob
This topic is locked and no more replies can be posted.