Forums

Email to an array of addresses

davideiandoli75 20 Jan, 2016
Hi to all,
I built a form in which I get an array of email addresses, and now I need to send a message to each one. I set up an Email action but it doesn't work putting the name of the array in 'Dynamic To' field. Is there - in Cf v5 - anything like Email[GH] action for Cf v4, which does exactly what I need? Thanks to all
davideiandoli75 08 Aug, 2016
I found this FAQ: http://www.chronoengine.com/faqs/2603-how-can-i-send-an-%3Cspan%20class= and I think it should help me. Actually I have to match records from two tables: Joomla users and CB Users; I only need email of users that match a particular condition, and here below there is the Custom Code by which I get the mail addresses I need:

<?php

   foreach ($form->data['scadenze'] as $n => $val) {
        
    $form->data['paramID'][] = $form->data['scadenze'][$n]['id']; /* registra l'id come parametro di ricerca */
    }
    $quanti = count($form->data['users']);

/* cerca tutti i valori dell'array e recupera gli indirizzi email */

    foreach ($form->data['paramID'] as $n => $val) {
    for ($i=0; $i < $quanti; $i++) {

/* quando ne trova uno ne registra l'indirizzo mail in un array che passa come parametro all'azione successiva */

    if ($form->data['paramID'][$n] == $form->data['users'][$i]['id']){
    $form->data['usermail'][]=$form->data['users'][$i]['email'];
    }
    }
    }

?>


Dragging a debugger action in my form I know that my 'usermail' array is working right; so I think it should be enough to write usermail in 'Dynamic To' field of my Email action, but actually it doesn't work. Thanks
GreyHead 08 Aug, 2016
Answer
Hi davideiandoli75,

Please try converting the array to a comma separated list and see if that will work . . .
. . .
$form->data['usermail'] = implode(',', $form->data['usermail']);
If it doesn't work then we can try another workaround.

Bob

PS Max included most of the functionality of my EMail [GH] action into the standard Email action in CFv5 so it never got re-written.
davideiandoli75 08 Aug, 2016
Very good Bob! Now it works! Thanks a lot

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