Home > Intermediate, PHP, Tutorials > Attaching Post-Submit PHP to Contact Form 7 Forms

Attaching Post-Submit PHP to Contact Form 7 Forms

One of the non-obvious features available in the Contact Form 7 plugin for WordPress are the hookswpcf7_before_send_mail” which gets fired right before the email is sent and “wpcf7_mail_sent” right after the email is sent.

Both of these actions are also sent as the first argument the WPCF7_contact_form object. print_r() on it and see what you get: some good stuff, particularly, $wpcf7_contact_form->posted_data is an associative array of the submitted data.

So include this code somewhere in a helper plugin or something and VOILA!

add_action('wpcf7_before_send_mail', 'do_post_submit_pre_mail_php');

function do_post_submit_pre_mail_php($form_obj) {
    print_r($form_obj->posted_data);
    return;
}

I haven’t checked into the other hooks, but these and the other customization available with Contact Form 7 make WordPress an even better tool for basic yet fully-featured Content Management System

Categories: Intermediate, PHP, Tutorials Tags:
  1. No comments yet.
  1. No trackbacks yet.