I am using the Ultimate Member plugin and I need CF7 to load the email of each user for sending that are within the public profiles that are the members.
Here I leave the code that I have used but it only works for me if I put an email in string format, $dynamic_email = 'mail@mail.com'; instead of $dynamic_email = $value;
How do I make the following dynamic code work for me?
function wpcf7_before_send_mail_function( $contact_form, $abort, $submission ) {
$form_id = $contact_form->id();
if($form_id == 799 ){
$valor = get_the_author_meta('user_email', um_profile_id()); // um_profile_id() - Profile ID in the Ultimate Member plugin
$dynamic_email = $valor;
$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 );
I need to load the value of get_the_author_meta('user_email', um_profile_id()) so that I upload the mail in each of the public profiles.
Thank you very much for the help.
Summarizing this function if it works, it manages to change the sending email and sends the form:
function wpcf7_before_send_mail_function( $contact_form, $abort, $submission ) {
$form_id = $contact_form->id();
if($form_id == 799 ){
$dynamic_email = 'mail@mail.com';
$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 );
This other one that is the one I need does not work and does not send the mail showing the error "An error occurred while trying to send your message. Please try again later." and I do not understand or know the reason why it does not work if I only make a small change and it also returns an email:
function wpcf7_before_send_mail_function( $contact_form, $abort, $submission ) {
$form_id = $contact_form->id();
if($form_id == 799 ){
$valor = get_the_author_meta('user_email', um_profile_id()); // um_profile_id() - Profile ID in the Ultimate Member plugin
$dynamic_email = $valor;
$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 );
Thanks for your help.