How to change recipient email on send event in Contact Form 7 (WordPress)

Hello everyone!

Sometimes you may need to send letter from your form on the your website to another recipient, for example user changed some parameters.

You can change recipient email with this hook:

function wpcf7_param_change_on_send($contact_form) {

    $custom_email = $_POST['some_field'];
    if(!empty($custom_email))
    {
      $mail = $contact_form->prop( 'mail' );
      $mail['recipient'] = $custom_email;
      $contact_form->set_properties(array('mail'=>$mail));
    }
}

add_action("wpcf7_before_send_mail", "wpcf7_param_change_on_send");

2 Responses to “How to change recipient email on send event in Contact Form 7 (WordPress)”

  1. could you explain what the $tech_email variable in the if statement is? Why did you define $field if it is not used in the function? Thanks.

    • segorev

      I apologize, I have made the mistake when I copied this code from my real project to the blog. You are right, the $field variable isn’t used in this code, but it is defined.
      The $field variable must contain the email from the POST query, and now I have fixed my code and replaced the wrongly named variables with the correct names.
      Instead of the $field and the $tech_email variables you should use only the $custom_email variable.

      Thank you for your comment!