Support » Plugin: Contact Form 7 » [Plugin: Contact Form 7] Modify posted data before sending

  • Resolved e


    I am trying to edit the $wpcf7 object data but it ignores it, this is the code:

    function wpcf7_modify_this(&$wpcf7_data) {
      $wpcf7_data->mail->recipient = "Mark <>";
    add_action("wpcf7_before_send_mail", "wpcf7_modify_this");

    I have been able to cancel emails by adding:
    $wpcf7_data->skip_mail = true;

    But changing any other parameter such as the recipient doesn’t work.

    Any ideas??

Viewing 7 replies - 1 through 7 (of 7 total)
  • e


    Ok, finally got it. It turns out the WPCF7 thing is an Object with Arrays inside so it should be called like:
    $wpcf7_data->mail['recipient'] = "Mark <>";

    Hope that helps 🙂



    what would you like to do with the posted data?



    Hi strigga,

    You can do pretty much anything, some examples:

    1) if the user typed in the word “support” or “help” you could change the recipient to, but if it found “business enquiry” forward it to

    2) Same goes for a City field, if the user is in London you could send the email to the London branch.

    3) Or if the form was submitted on a weekend, when the offices are closed, you can send a confirmation email like “Thanks for your email, unfortunately we are out of the office, will get back to you on Monday“.

    4) If there is a budget field and the user types in “1,000” then forward it to, but if the user types in “10,000,000” then the boss will probably want to deal with that juicy client himself.

    There’s plenty of examples really, the idea is to have fewer forms on the site (or even just one) which then through some smart coding can do custom actions or change certain things.



    Very handy, cheers mate



    @ e

    What to do when you have multiple forms (contact forms and apply forms) on you’re website? How do you determine when this function must be executed? My custom before mail send function should only be executed with the apply forms.



    @ toomaat

    Each form has an ID: $wpcf7_data->id so once you know the ID of the Apply forms you can put a conditional if($wpcf7_data->id == 123) and take action only for that form




    In the mean time I also found the solution ‘how to handle with multiple forms”.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘[Plugin: Contact Form 7] Modify posted data before sending’ is closed to new replies.