For example, you receive a POST ID as a parameter, and you want to add the title of the post in the body of the email sent by Contact Form 7.
You can add the text [my_post_id] in the body of the form configuration from the admin dashboard.
Then replace it with the data you need, in this case the title, using the filer wpcf7_mail_components.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
add_filter( 'wpcf7_mail_components', 'custom_mail_components');
 
function custom_mail_components($wpcf7_data, $form = null) {
 
     if( isset( $_GET['my_post_id'] ) ){
 
        $post = get_post( $_GET['my_post_id'], ARRAY_A );
 
        $str = $post['post_title']. ' ' . get_permalink( $_GET['my_post_id'] ) ;
	$wpcf7_data['body'] = str_replace('[my_post_id]', $str , $wpcf7_data['body'] );
     }
 
     return $wpcf7_data;
}
Contact Form 7, change texts on email body
Tagged on:

Leave a Reply

Your email address will not be published. Required fields are marked *