<?php

require_once DIRLIBCOMP . 'MailChimp.php';
//$mailchimp_key = '52ddcdb27ecf3ada35507f522ac22fae-us3';
$mailchimp_key = '17c27bcada8190a2911ad6c9432328f7-us19';

$MailChimp = new MailChimp($mailchimp_key);

if ($newsletter) {
    $result = $MailChimp->post("lists/487452db7a/members", [
        'email_address' => $email,
        'status'        => 'subscribed',
        'merge_fields'  => array(
            'FNAME'   => $nombre,
            'LNAME'   => $apellidos,
            'MMERGE4' => $telefono,
            'MMERGE5' => $servicio,
            'MMERGE6' => $fecha_reserva,
        ),
    ]);

    $sentencia = "LOCALIZADOR - " . $localizador . " Resultado mailchimp: " . $result;
    Insertar_Sentencia($sentencia, 'compra');
}
