Forums

send mail using addresses from db

mic0672 23 Jul, 2014
Hi,
I have read many posts but have not found what I'm looking.
I created a form to insert items. When you create an article, I would like to send an email notification to a user group. Using dbread user can read the email. I have inserted an "email action" in the form. How do I insert the db values in the field "TO" or "BCC" of the "email action"?
thanks
Mike
GreyHead 23 Jul, 2014
Hi Mike,

I believe that the CFv5 Email action will accept an array of email addresses so you would need to use the DB Read to get all the addresses for the specified group; possibly use a Custom Code action to tidy those up into a clean sub array in the $form->data array and then add the name of the sub-array to the Dynamic To box of the Email action (or possibly the Dynamic BCC box if you don't want to share the addresses).

This should work OK provided that the numbers in each group are relatively small. Otherwise linking to a specialist email extension or service might be a better solution.

Bob
mic0672 23 Jul, 2014
thanks, Bob,
how do I manage the data read from the db? How do I insert them into a sub array?
Max_admin 23 Jul, 2014
Hi Mike,

How did you read the emails ? please add a debugger action before the "Email" action and post the data array here!

Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
mic0672 23 Jul, 2014
Hi Max
this is the result of the debug:


Array
(
    [option] => com_chronoforms5
    [chronoform] => aggiungi_circolare
    [event] => submit
    [Itemid] => 
    [circolari] => Array
        (
            [title] => Lorem ipsum
            [introtext] => <p><span style="font-family: Arial, Helvetica, sans; line-height: 14px; text-align: justify;">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam at ipsum nec nibh fermentum molestie. Donec bibendum, augue non blandit rutrum, dolor velit ornare eros, eget blandit lectus massa a est. In mattis eros congue volutpat fringilla. Etiam vehicula risus a sollicitudin egestas. Pellentesque ullamcorper sollicitudin tortor, in sollicitudin nibh blandit eu. Nunc fringilla sem ac magna adipiscing, vitae aliquam arcu iaculis. Fusce a nisl ut nisi congue sodales non non massa. Mauris imperdiet faucibus eros, a vehicula ipsum pharetra posuere. Duis varius mattis semper. Vestibulum viverra orci a nulla sagittis molestie. In fringilla dui lectus. Suspendisse potenti. Phasellus adipiscing orci ac lacinia mattis.</span></p>
            [catid] => 12
            [id] => 
            [metakey] => 
            [state] => 1
        )

    [metakey] => Array
        (
            [0] => ATA
        )

    [invia] => invia
    [mail] => Array
        (
            [0] => Array
                (
                    [id] => 1093
                    [email] => 7780985@nomail.it
                )

            [1] => Array
                (
                    [id] => 1090
                    [email] => dsdsdsd@nomail.it
                )

            [2] => Array
                (
                    [id] => 1089
                    [email] => 3619403@nomail.it
                )

            [3] => Array
                (
                    [id] => 1088
                    [email] => dsdsuiuiusds@nomail.it
                )

            [4] => Array
                (
                    [id] => 1073
                    [email] => dffdfdfd@nomail.it
                )

            [5] => Array
                (
                    [id] => 1070
                    [email] => 2572787@nomail.it
                )

            [6] => Array
                (
                    [id] => 1063
                    [email] => 9830321@nomail.it
                )

            [7] => Array
                (
                    [id] => 1061
                    [email] => 8976777@nomail.it
                )

            [8] => Array
                (
                    [id] => 1058
                    [email] => 6765453@nomail.it
                )

            [9] => Array
                (
                    [id] => 1051
                    [email] => 1527719@nomail.it
                )

            [10] => Array
                (
                    [id] => 1045
                    [email] => 7159311@nomail.it
                )

            [11] => Array
                (
                    [id] => 1044
                    [email] => 2887781@nomail.it
                )
       
        )
)
GreyHead 23 Jul, 2014
Answer
1 Likes
Hi mic0672,

So you need to add a Custom Code action after the DB Read and before the Email action to pull the email addresses out of the data you have there. It will be something like this:
<?php
$emails = array();
foreach ( $form->data['mail'] as $m ) {
  $emails[] = $m['email'];
}
// uncomment the following line if you need a list instead of an array 
// $emails = implode(',', $emails);
$form->data['email_list'] = $emails;
?>

Then put email_list into the Dynamic To (or Dynamic BCC) box in the email action.

Bob
mic0672 25 Jul, 2014
it works very well.
thanks
This topic is locked and no more replies can be posted.