Fxmly92
Fxmly92

Reputation: 11

Gravity form | Get the sender email to fire a notification

In order to send a post form submission notification with wp_mail(), I would like to get the sender email.

I have created an hidden field into my form where I can get the user logged email. What is the function I can use to get the user logged email to send the notification ?

The hidden field ID into the form is 4. I have created a variable :

$subscribers = rgar( $entry, '4' );

But it's not working...

My code to send the notification :

add_action( 'gform_after_submission', 'notification_mail', 10, 2 );

function notification_mail( $entry, $form ) {

$created_posts = gform_get_meta( $entry['id'], 'gravityformsadvancedpostcreation_post_id' );

foreach ( $created_posts as $post )
    {   
        $post_id = $post['post_id'];
        $subscribers = rgar( $entry, '4' ); 
        $subject     = 'Merci';
        $message     = "<p>Bonjour,</p>
            <p>Merci d'avoir rempli notre formulaire</p>";
        $headers = array('Content-Type: text/html; charset=UTF-8','From: SMP <[email protected]>');
        $content_type = function() { return 'text/html'; };
        
        add_filter( 'wp_mail_content_type', $content_type );
        wp_mail( $subscribers, $subject, $message, $headers );
        remove_filter( 'wp_mail_content_type', $content_type );
    }
    

}

Thank you so much ! FX

Upvotes: 0

Views: 216

Answers (1)

Fxmly92
Fxmly92

Reputation: 11

Ok... I just wrote this function to get the user mail (my user is logged when he complets the form) :

$user = wp_get_current_user();
$subscriber = esc_html( $user->user_email ); 

Upvotes: 0

Related Questions