Integration with MailChimp

0

Well I'm doing an integration with MailChimp, using this code:

require('src/Mailchimp.php');
define('MAILCHIMP_API_KEY',  '6db8ab94ce74d88a289f9068768d7179-us9'); // Mailchimp API KEY
define('MAILCHIMP_LIST_ID',  'c825a91eb8'); // ID Lista
define('MAILCHIMP_CITY_TAG', 'MERGE1'); // Tag Do campo

$email = [
        'email' => "[email protected]",
    ];
$merge = [
        MAILCHIMP_CITY_TAG => "testando",
    ];

try {
    $mailchimp = new Mailchimp(MAILCHIMP_API_KEY);
    $lists = new Mailchimp_Lists($mailchimp);


$lists->subscribe(
  MAILCHIMP_LIST_ID, // Lista id
  $email,            // Email
  $merge,            // Campo personalizado
  'html',            // Tipo de Email
  false              // Confirmação email


 );
echo 'Sucesso!';



  } catch (Mailchimp_List_AlreadySubscribed $e) {
    echo 'Você já assinou essa lista!.';
  } catch (Mailchimp_Email_NotExists $e) {
    echo 'O e-mail informado não existe.';
  } catch (Mailchimp_Invalid_Email $e) {
    echo 'O e-mail informado é inválido.';
  } catch (Mailchimp_List_InvalidImport $e) {
    echo 'Dados inválidos, provavelmente seu e-mail.';
  } 
    catch (Exception $e) {
    print_r($e);
  }

But I have a table in the database that contains the customer's KEY API and the list ID. That is, I want to get the values from the database, save them in a variable and set them with those values. Does anyone know how I can do this?

    
asked by anonymous 16.04.2015 / 21:03

1 answer

0

I solved using this code:

require('src/Mailchimp.php');
$apikey = '6db8ab94ce74d88a289f9068768d7179-us9';
$merge_vars =  array('MERGE1' => 'testando');
$email = '[email protected]';
$listid = 'c825a91eb8';
$MailChimp = new Mailchimp($apikey);
$result = $MailChimp->lists->subscribe($listid,
                                    array('email'=>$email),
                                    $merge_vars,
                                    false,
                                    false,
                                    false,
                                    false
                                   );
    
17.04.2015 / 14:37