Skip to content

Instantly share code, notes, and snippets.

@coder618
Created May 26, 2020 12:23
Show Gist options
  • Save coder618/5747d1e68eeb8148c07a0bcccda46377 to your computer and use it in GitHub Desktop.
Save coder618/5747d1e68eeb8148c07a0bcccda46377 to your computer and use it in GitHub Desktop.
Mailchimp Add E-Email Address CURL PHP
<?php
// require 'auth.php';
$username = 'username';
$password = 'password';
$url = 'https://us19.api.mailchimp.com';
// $postvars = "[email protected]&status=subscribed";
$postvars = [
"email_address"=> "[email protected]",
"status"=> "subscribed",
"merge_fields" => [
"FNAME"=> "Aziz anawar",
"DEPT" => "CSE",
"PHONE" => "+9898797",
"ROLE" =>"STUDENT"
]
];
$postvars = json_encode($postvars);
// var_dump($postvars);
// die();
$url = "https://us19.api.mailchimp.com/3.0/lists/listID/members/";
// $url = "http://localhost/temp/post.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$postvars);
$result = curl_exec($ch);
curl_close($ch);
echo($result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment