I'm trying to replace the email recipient in the Contacnt Form 7 plugin with the value from the Advanced Custom Fields plugin, because I have a dynamic recipient in each record. I found a function on the internet, but it doesn't work for me, the form returns a sending error.
function wpcf7_before_send_mail_function( $contact_form, $abort, $submission ) {
global $post;
$dynamic_email = get_field('form_email',$post->ID); // get your email address...
$properties = $contact_form->get_properties();
$properties['mail']['recipient'] = $dynamic_email;
$contact_form->set_properties($properties);
return $contact_form;
}
add_filter( 'wpcf7_before_send_mail', 'wpcf7_before_send_mail_function', 10, 3 );
Maybe there's a simpler function that works, or is there something I'm doing wrong?