<?php $checked = $hook->getValue('newsletter'); $fname = $hook->getValue('fname'); $lname = $hook->getValue('lname'); $email = $hook->getValue('email'); $listId = $hook->getValue('listid'); $apiKey = "TheAPIkeyinMailchimp"; $server = "us2"; if ($checked == "Yes") { $memberId = md5(strtolower($email)); print $url = 'https://' . $server . '.api.mailchimp.com/3.0/lists/' . $listId . '/members/' . $memberId; $data = array( 'email_address'=>$email, 'status' => 'pending', 'merge_fields' => [ 'FNAME' => $fname, 'LNAME' => $lname ] ); $jsonString = json_encode($data); $ch = curl_init($url); curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $apiKey); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonString); $result = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); }
This question has been answered by sitsol. See the first response.