Fires an action hook right after the email(s) have been sent.
Parameters
- $post_id
int Post contact form lives on.
- $to
(string | array) Array of valid email addresses, or single email address.
- $subject
string Feedback email subject.
- $message
string Feedback email message.
- $headers
(string | array) Optional. Additional headers.
- $all_values
array Contact form fields.
- $extra_values
array Contact form fields not included in $all_values
Changelog
- Introduced in Jetpack 7.3.0
How to use this hook
Notes
One can use this hook to trigger an event after a contact form submission, when the notification email has been sent.
/**
* When a contact form is submitted on a specific page on the site (page ID 99 in this example),
* increment a counter in a local option.
*
* @param int $post_id Post contact form lives on.
* @param string|array $to Array of valid email addresses, or single email address.
* @param string $subject Feedback email subject.
* @param string $message Feedback email message.
* @param string|array $headers Optional. Additional headers.
* @param array $all_values Contact form fields.
* @param array $extra_values Contact form fields not included in $all_values
*/
add_action(
'grunion_after_message_sent',
function ( $post_id, $to, $subject, $message, $headers, $all_values, $extra_values ) {
// If we are not on the right page, bail early.
if ( 99 !== $post_id ) {
return;
}
// Get the current counter value.
$counter = get_option( 'contact_form_submission_counter', 0 );
// Increment the counter.
$counter++;
// Update the counter value.
update_option( 'contact_form_submission_counter', $counter );
}
);