Support » Plugin: Contact Form 7 » Does CF7 not have any API?

  • Hi, I need to alter the TO and BCC of emails sent with CF7 when the mail is sent
    I can’t find any API docs at all.

    I solved it with a cumbersome JS solution that populates a hidden email field which I then use in CF form as a “CF ShortCode”.
    This is suboptimal at best, totally uncontrollable and if someone does have JS disabled on the browser a complete failure.

    So I would like to use the PHP api, it would be the right way to do this.
    Any hook we can use?

    Something like “wpcf7_send_mail” or whatever that offers us form ID, receivers, body etc of the mail…

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi, Beda, I’m another Contact Form 7 user.

    Try examining the wpcf7_before_send_mail hook.

    You can find some examples online that demonstrate the ability to modify the “to” and “bcc” fields.

    Here is a rough example for demo purposes:

    add_action('wpcf7_before_send_mail','change_recipient');
    
    function change_recipient($wpcf){
    
            $currentformInstance  = WPCF7_ContactForm::get_current();
    
            $mail = $currentformInstance->prop('mail');
    			
    	$mail['recipient'] = "test@test.com";
    		
    	$currentformInstance->set_properties(array(
    		"mail" => $mail
    	));
    
    	return $currentformInstance;
    }
    Thread Starter Beda

    (@bedas)

    Hi @plantprogrammer – I will try this, thanks.

    But it is a bit weird or I would say frowned upon to use hooks that are not officially documented.
    Yes, I could and can read the code to find the hooks, but not being documented also means the developer might just change them or their behaviour at any point.

    I would really hope for the Devs here to confirm we can use that, and well.. a DEV doc would be amazing I think

    Thanks again for the input, I will try that (looks like exactly what I need) and confirm if it works.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.