Do action hook for email sent

Posted by on Aug 23, 2013 in How To

There is a do action hook ‘fsctf_mail_sent’ for adding your own custom action for after the email is sent. This applies to the WordPress version only.
This function is used by the WordPress plugin “Contact Form DB” to save the email to a database. And by Fast Secure Contact Form Newsletter.

You can use the action hook to perform a custom action, like send a SMS email message, save data to the database, etc.

Add the following code to your theme’s functions.php file or to a custom plugin.
Be sure to set the setting in the function to control which forms you want this on.
These filters only work with versions 4.xx and up, not the 3.xx versions or lower.

Note: you have to put your own custom code in the function, or make your own plugin.


function my_process_fsctf_mail_sent($form) {

##################################
 // control which forms you want this on
 $all_forms = true; // set to true for process on all forms, or false to use settings below
 $forms = array('1','2');  // one or more individual forms
 ##################################
 if ( !in_array($form->form_number, $forms) && $all_forms != true)
 return;

foreach ($form->posted_data as $name => $value) { 

 //do whatever code you want here

}

// do not return a string, because this is only an action hook
return;

} // end function
// Hook into Fast Secure Contact Form after email sent
add_action('fsctf_mail_sent', array(&$this, 'my_process_fsctf_mail_sent'));

Maybe you want to run different code based on form number

Use this function instead:


function my_process_fsctf_mail_sent($form) {

##################################
 // control which forms you want this on
 $all_forms = false; // set to true for process on all forms, or false to use settings below
 $forms = array('1','2');  // one or more individual forms
 ##################################
 if ( !in_array($form->form_number, $forms) && $all_forms != true)
 return;

if ( $form->form_number == 1 ) {
  foreach ($form->posted_data as $name => $value) { 

     //do whatever code A you want here

  }
}

if ( $form->form_number == 2 ) {
  foreach ($form->posted_data as $name => $value) { 

     //do whatever code B you want here

  }
}

// do not return a string, because this is only an action hook
return;

} // end function
// Hook into Fast Secure Contact Form after email sent
add_action('fsctf_mail_sent', 'my_process_fsctf_mail_sent');

Do you need help?

Send us a Donation:

Donate to Mike Challis