<?php
add_action( 'wpcf7_mail_sent', 'action__wpcf7_mail_sent' );
function action__wpcf7_mail_sent( $contact_form ) {
$title = $contact_form->title();
$submission = WPCF7_Submission::get_instance();
if ( $submission ) {
$posted_data = $submission->get_posted_data();
}
function post_to_url( $url, $data ) {
$fields = '';
foreach( $data as $key => $value ) {
$fields .= $key . '=' . $value . '&';
}
rtrim( $fields, '&' );
$timeout = 30;
$post = curl_init();
curl_setopt($post, CURLOPT_URL, $url);
curl_setopt($post, CURLOPT_HEADER, 0);
curl_setopt ($post, CURLOPT_TIMEOUT, $timeout);
curl_setopt ($post, CURLOPT_USERAGENT, sprintf("Mozilla/%d.0",rand(4,5)));
curl_setopt ($post, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($post, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($post, CURLOPT_POST, true);
curl_setopt($post, CURLOPT_POSTFIELDS, ($fields));
curl_setopt($post, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($post, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($post);
curl_close($post);
}
if ( 'your contact form title' == $title ) {
//you will get data in $posted_data variable
//echo "<pre>"; print_r($posted_data);
$data = $posted_data;
$final_url = "your_api_url";
post_to_url( $final_url, $data );
}
}
попробуйте использовать этот хук wpcf7_mail_sent