I tested a script to integrate forms with Mailchimp:
<?php
// MailChimp API URL
$memberID = md5(strtolower($email_popup));
$dataCenter = substr($apiKey,strpos($apiKey,'-')+1);
$url = 'https://' . $dataCenter . '.api.mailchimp.com/3.0/lists/' . $listID . '/members/' . $memberID;
// member information
$json = json_encode([
'email_address' => $email_popup,
'status' => 'subscribed',
'merge_fields' => [
'FNAME' => $nome_empresa_popup,
'CIDADE' => $cidade_estado_popup,
'MMERGE4' => $vendedor_popup
]
]);
// send a HTTP POST request with curl
$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, $json);
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
?>
On my site's server, it worked correctly.
But on the client server, you are giving the following error:
Parse error: syntax error, unexpected '[', expecting ')' in /home/{domain}/public_html/{site}/paginas/modal.php on line 511
What's in this line:
$json = json_encode([
I looked in the PHP documentation for something, but found nothing concerning the syntax error.