CFv6 version
Supposing your dropdown field or radio button is named "user_email", go under "Events" > "Logic" and drag a "Switch" action to the "submit" event, make sure the new switch action is BEFORE (above) the "Email" action.
In the "Data provider" field of the "Switch" action write: {data:user_email}
In the "Values setup" enter multiple lines, each of them in this format: dropdown_value:email_address
em1:first@domain.com em2:second@domain.com em3:third@domain.com
Now set the "Switch" action "Name" to "email_address" for example, in your "Email" action "Recipients" just write {var:email_address} to capture the result of the switch action which is an email address.
CFV5 version
em1=This address em2=That address em3=The other address
<?php
// set a default recipient
$recipient = 'em1';
if ( isset($form->data['recipients']) && $form->data['recipients'] ) {
$recipient = $form->data['recipients'];
}
$emails = array (
'em1' => 'bob@example.com',
'em2' => 'info@example.net',
'em3' => 'admin@example.com' );
$form->data['email_to_use'] = $emails[$recipient];
?>
OR if you want the user to be able to select more than one address. In this case my form has a select dropdown or checkbox group named recipients[].
// set a default recipient
$recipients = array( 'em1' );
if ( !empty( $form->data['recipients'] ) ) {
$recipients = $form->data['recipients'];
}
$emails = array (
'em1' => 'bob@example.com',
'em2' => 'info@example.net',
'em3' => 'admin@example.com'
);
$emails_to_use = array();
foreach ( $recipients as $v ) {
$emails_to_use[] = $emails[$v];
}
$emails_to_use = implode(',', $emails_to_use);
$form->data['emails_to_use'] = $emails_to_use;
?>
<?php
// set a default recipient
$recipients = array( 'em1' );
if ( isset($form->data['recipients']) && $form->data['recipients'] ) {
$recipients = $form->data['recipients'];
}
$emails = array (
'em1' => array('bob@example.com', 'john@example.com'),
'em2' => array('info@example.net'),
'em3' => array('admin@example.com', 'admin@example.org')
);
$emails_to_use = array();
foreach ( $recipients as $v ) {
$emails_to_use = array_merge($emails[$v], $emails_to_use);
}
$emails_to_use = implode(',', $emails_to_use);
$form->data['emails_to_use'] = $emails_to_use;
?>
<?php
if ( !empty($form->data['email2']) ) {
$mailto = array($form->data['email1'], $form->data['email2']);
$mailto = implode(',', $mailto);
} else {
$mailto = $form->data['email1'];
}
$form->data['email_to_use'] = $mailto;
?>
c) Also in the OnSubmit event after the Custom Code action I have an Email action with the Dynamic To box on the Advanced tab set to email_to_use or emails_to_use The email action is enabled and has standard Static values for Subject, From Name and From Email.
CFV4 version
em1=This address em2=That address em3=The other address
<?php
$recipient = JRequest::getString('recipients', 'em1', 'post');
$emails = array (
'em1' => 'bob@example.com',
'em2' => 'info@example.net',
'em3' => 'admin@example.com' );
$form->data['email_to_use'] = $emails[$recipient];
?>
For ChronoForms v3 and earlier
First include the following in your Form HTML:
. . . Select the recipient you wish to contact: <select name="recipients"> <option value="em1">Name 1 <option value="em2">Name 2 <option value="em3">Name 3 . . . </select> . . .
Then enter this code in the 'On Submit code - before sending email' field:
For ChronoForms 3.1 and 3.2
<?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']]);
?>
For ChronoForms v3.0
<?php
$emails_2 = array('em1'=>'sample1@email.com', 'em2'=>'sample2@email.com', 'em3'=>'name_3@example.com', . . .);
$emails[0]->to .= ','.$emails_2[$_POST['recipients']];
?>
For ChronoForms 2.5.x and earlier
<?php $emails = array( 'em1'=>'name_1@example.com', 'em2'=>'name_2@example.com', 'em3'=>'name_3@example.com', . . . ); $rows[0]->extraemail = $emails[$_POST['recipients']]; ?>
Thanks to deafjoomla.com for the original version of this FAQ

Comments: