Forums

Multiple email recipients depending on checkboxes

pehck 14 Jan, 2010
After reading FAQ31 and related postings in the forum, I still cannot figure out how to modify the code in FAQ31 to get this work.

Let say in the form I have


<input value="em1" type="checkbox" name="check[]" />
<label for="check1"">Sample 1</label>

<input value="em2" type="checkbox" name="check[]" />
<label for="check2">Sample 2</label>

<input value="em3" type="checkbox" name="check[]" />
<label for="check3">Sample 3</label>



The code in FAQ31 to enter in 'On Submit code - before sending email' field is:



<?php
$emails_2 = array('em1'=>'sample1@email.com', 'em2'=>'sample2@email.com', 'em3'=>'name_3@example.com', . . .);
$MyForm =& CFChronoForm::getInstance('form_name_here');
$MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
$MyFormEmails->setEmailData(1, 'to', $emails_2[$_POST['recipients']]);
?> 



Now the question is how should I modify the code above so that it works for multiple recipients based on checkboxes. I'm using ChronoForms v3.1
GreyHead 14 Jan, 2010
Hi pehck,

You;ll need to match up the names of the fields between the two snippets, and if you are allowing several emails to be selected you'll need to match up all the names in the array with the corresponding emails.

If I recall correctly I posted a fuller solution to this a week or so ago (though maybe not for multiple emails).

Bob

Don't forget to replace '. . .' in the email array with the correct list of addresses.
ikookmaar 01 Mar, 2010
I have searched everywhere and have yet failed to get this working...
Also I couldn't find the "fuller solution" Greyhead mentions.
I really don't understand enough PHP to figure this out myself, or to combine the snippets of information on this to a working solution.
Besides I found a lot of other people asking the same thing (how to use checkboxes for multiple recipients without displaying their email adresses).
So if any one of you has a working form (with checkboxes for multiple recipients), could you please post it (among the shared forms) or add this information to faq#31 (Greyhead)?

Thank you!
This topic is locked and no more replies can be posted.