add_action(‘wpcf7_mail_sent’, ‘send_cf7_to_erp_crm’);
function send_cf7_to_erp_crm($contact_form) {
$submission = WPCF7_Submission::get_instance();
if (!$submission) return;
$data = $submission->get_posted_data();
$body = [
‘first_name’ => $data[‘your-name’],
’email’ => $data[‘your-email’],
‘phone’ => isset($data[‘your-phone’]) ? $data[‘your-phone’] : ”,
‘notes’ => $data[‘your-message’]
];
wp_remote_post(‘https://dmc-consulting.info/wp-json/erp/v1/crm/contacts’, [
‘method’ => ‘POST’,
‘headers’ => [
‘Authorization’ => ‘Basic ‘ . base64_encode(‘API_USER:API_PASSWORD’),
‘Content-Type’ => ‘application/json’
],
‘body’ => json_encode($body)
]);
}