Title: Dynamic CC Additional Header
Last modified: October 18, 2021

---

# Dynamic CC Additional Header

 *  Resolved [robrandell](https://wordpress.org/support/users/robrandell/)
 * (@robrandell)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/dynamic-cc-additional-header/)
 * Hi,
    I am attempting to add an additional ‘cc’ header to the email being sent
   via CF7 coupled with ACF custom field. However, the email sends successfully 
   without the ‘cc’ added. Perhaps been staring at it for too long, but I can’t 
   figure it out as yet. Code below in ‘functions.php’.
 *     ```
       function add_jobmanager_recipient( $cf7 ) {
   
           global $post;
           $submission = WPCF7_Submission::get_instance();
   
       	if ( $submission ) {
       		$data = $submission->get_posted_data();
               $cc_email = get_field( 'job_contact_email_address', $post->ID );
   
       		if ( empty( $data ) || empty( $cc_email ) ) {
       			return;
               }
   
       		$mail = $cf7->get_properties();
       		$mail[ 'mail' ][ 'additional_headers' ] .= "\r\nCc: $cc_email";
   
       		$cf7->set_properties( $mail );
           }
           return $cf7;
       }
       add_action( 'wpcf7_before_send_mail', ' add_jobmanager_recipient', 20, 2 );
       ```
   
 * Thanks for any pointers.
 * Cheers,
    Rob —

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Takayuki Miyoshi](https://wordpress.org/support/users/takayukister/)
 * (@takayukister)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/dynamic-cc-additional-header/#post-14982834)
 * You have 2 mistakes here:
 * `add_action( 'wpcf7_before_send_mail', ' add_jobmanager_recipient', 20, 2 );`
 *  Thread Starter [robrandell](https://wordpress.org/support/users/robrandell/)
 * (@robrandell)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/dynamic-cc-additional-header/#post-14984209)
 * Thanks. I knew I was staring at it for too long.
    The other problem was the `
   $post->ID` was a null object, so I switched it to get the meta data of the submission,
   specifically the `container_post_id`. Final code below if it helps anyone else.
 *     ```
       function add_jobmanager_recipient($cf7)
       {
           $submission = WPCF7_Submission::get_instance();
   
           if ($submission) {
               $data = $submission->get_posted_data();
               $cc_email = get_field(
                   'job_contact_email_address',
                   $submission->get_meta('container_post_id')
               );
   
               if (empty($data) || empty($cc_email)) {
                   return;
               }
   
               $mail = $cf7->get_properties();
               $mail['mail']['additional_headers'] .= "\r\nCc: $cc_email";
   
               $cf7->set_properties($mail);
           }
           return $cf7;
       }
       add_filter('wpcf7_before_send_mail', 'add_jobmanager_recipient', 10, 1);
       ```
   
 * Thanks,
    Rob —

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Dynamic CC Additional Header’ is closed to new replies.

 * ![](https://ps.w.org/contact-form-7/assets/icon.svg?rev=2339255)
 * [Contact Form 7](https://wordpress.org/plugins/contact-form-7/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/contact-form-7/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/contact-form-7/)
 * [Active Topics](https://wordpress.org/support/plugin/contact-form-7/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contact-form-7/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contact-form-7/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [robrandell](https://wordpress.org/support/users/robrandell/)
 * Last activity: [4 years, 7 months ago](https://wordpress.org/support/topic/dynamic-cc-additional-header/#post-14984209)
 * Status: resolved