Contact Form 7
Where do I add a hook to be executed before a mail is sent? (4 posts)

  1. lata_dev
    Posted 5 years ago #

    I am using Contact Form 7 to send an email whenever someone wants to contact me. It works great. Now I'd also like to create a contact in a db whenever someone tries to contact me.

    From what I read, I created a function which does this and the function works (tried calling it in a static file). But I cannot understand where to add the function call. I added this statement to functions.php in the plugin's admin folder

    add_action('wpcf7_before_send_mail', 'myFunction');

    But the function is not called. I even tried adding it to classes.php but it doesn't get called from there either. The function is as follows

    function myFunction($cf7){
        $firstName = $cf7->posted_data["first_name"];
        $lastName = $cf7->posted_data["last_name"];
        $emailAddr = $cf7->posted_data["email"];
        $companyName = $cf7->posted_data["company"];
        $urlAddr = $cf7->posted_data["URL"];
        $designation = $cf7->posted_data["title"];
        //add data to the database here

    Would really appreciate some help. I do not know about wordpress development so cannot be certain if I'm adding the action at the right place.



  2. Takayuki Miyoshi
    Plugin Author

    Posted 5 years ago #

    Checking out how msimpson's Contact Form 7 to Database Extension does it will help.

  3. lata_dev
    Posted 5 years ago #

    Thanks. In the extension, they are adding all actions as
    add_action('wpcf7_before_send_mail', array(&$this, 'saveFormData'));

    But from what I read in the posts in this forum, they add it with just the function name i.e.

    add_action('wpcf7_before_send_mail', 'myFunction');

    How do these 2 actions differ?

  4. Takayuki Miyoshi
    Plugin Author

    Posted 5 years ago #

    array(&$this, 'saveFormData')

    This is not just a function, but an object method call.

    Functionally, not so different.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Contact Form 7
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic