Replace admin email recipient by acf email value
-
hello
1 i create a form with forminator with an hidden field and value {adresse_mail_de_contact}
2 i add it in article with an acf field adresse_mail_de_contactmy goal is to remplace admin email by adresse_mail_de_contact value
i create a a function
add_filter( 'forminator_custom_form_mail_admin_recipients', 'wpmudev_change_admin_email_recipient', 10, 4 );
function wpmudev_change_admin_email_recipient( $recipients, $custom_form, $data, $entry ) {
// Récupérer l'ID du formulaire
$form_id = is_object( $custom_form ) && isset( $custom_form->id ) ? $custom_form->id : 0;
// Filtre sur le formulaire spécifique
if( $form_id != 37463 ) {
return $recipients;
}
// Récupérer l'ID de la page/article
$post_id = 0;
if( isset( $_REQUEST['page_id'] ) ) {
$post_id = intval( $_REQUEST['page_id'] );
} elseif( isset( $_POST['page_id'] ) ) {
$post_id = intval( $_POST['page_id'] );
} elseif( isset( $_SERVER['HTTP_REFERER'] ) ) {
$post_id = url_to_postid( $_SERVER['HTTP_REFERER'] );
}
if( $post_id > 0 ) {
$email_contact = get_field( 'adresse_mail_de_contact', $post_id );
// Vérifier que l'email est valide
if( !empty( $email_contact ) && is_email( $email_contact ) ) {
// Remplacer tous les destinataires par l'email du champ ACF
$recipients = array( $email_contact );
}
}
return $recipients;
}But doesn’t works, what i doing wrong ?
regards
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘Replace admin email recipient by acf email value’ is closed to new replies.