Buongiorno
Sto inserendo mailchimp su un sito per poter raccogliere le email di chi vuole registrarsi alla newsletter.
Riesco a fare tutto senza problemi con un modulo custom utilizzando le api.
Vorrei solo aggiungere in automatico il tags ma non capisco come posso fare.
Questo è il codice che ho fino ad ora:
codice:
$email = $_POST["email"];
$list_id = 'id della lista dove far finire l'indirizzo email';
$api_key = 'mia api key';
$data_center = substr($api_key,strpos($api_key,'-')+1);
$url = 'https://'. $data_center .'.api.mailchimp.com/3.0/lists/'. $list_id .'/members';
$json = json_encode([
'email_address' => $email,
'status' => 'subscribed', //pass 'subscribed' or 'pending',
]);
try {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $api_key);
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_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$result = curl_exec($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if (200 == $status_code) {
echo "<div class=\"alert alert-success\" role=\"alert\">Grazie per esserti registrato</div>";
}
else{
echo "<div class=\"alert alert-danger\" role=\"alert\">email già presente</div>";
}
} catch(Exception $e) {
echo $e->getMessage();
}
sto provando a modificare la parte della variabile json cosi' ma non va:
codice:
$json = json_encode([
'email_address' => $email,
'status' => 'subscribed',
'tags' => 'miotag',
]);
come potrei fare?
Grazie