Integration with Mailchimp

Asked

Viewed 565 times

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 client’s KEY API and the list ID. That is, I want to take the values of the database, save them in a variable and define them with these values. Does anyone know how I can do it?

  • Which database?

  • Mysql, but the problem is not in the database. I can capture these values all right, saved them in variables also all right, what I want to know is how specific API KEY receives the value of this variable. Because I can only set that value with the defines.

  • Good, and you can’t replace the define by variables with these bank values?

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
                                   );

Browser other questions tagged

You are not signed in. Login or sign up in order to post.