This is possible using the pipes code… see: https://contactform7.com/selectable-recipient-with-pipes/
If this doesn’t work, you may need to create a new action:
add_action('wpcf7_before_send_mail', 'custom_wpcf7_before_send_mail');
and handle recipients here based on conditions from form post. Example:
add_action('wpcf7_before_send_mail', 'custom_wpcf7_before_send_mail');
function custom_wpcf7_before_send_mail($form) {
$wpcf7 = WPCF7_ContactForm::get_current();
$submission = WPCF7_Submission::get_instance();
$data = $submission->get_posted_data();
if(empty($data)) return;
// assuming this is a post of an array of CHECKBOXES -- named "recipients" with email addresses of values. NOTE: See NOTE, below code.
$recipients = isset($data['recipients']) ? $data['recipients'] : false;
$recipientsList = array();
if($recipients) {
foreach($recipients as $recipient) {
$recipientsList[] = $recipient;
}
}
$mail = $wpcf7->prop('mail');
$mail['recipient'] = implode(",", $recipientsList);
$wpcf7->set_properties(array("mail" => $mail));
return $wpcf7;
}
NOTE: I highly suggest against using email addresses in values of HTML elements due to web scrapers/spammers. Instead, use something else like ID #’s or names, then reference them back in your code and then setup the recipients.