Updating email addresses with Mailchimp’s API

use \DrewM\MailChimp\MailChimp;
$MailChimp = new MailChimp('abc123abc123abc123abc123abc123-us1');
$list_id = 'b1234346';
$subscriber_hash = $MailChimp -> subscriberHash('currentemail@example.com');
$endpoint = 'lists/'.$listID.'/members/'.$subscriber_hash;
$MailChimp -> patch($endpoint, [
'email_address' => 'newemail@example.com'
]);
$MailChimp -> delete($endpoint);
$newendpoint = 'lists/'.$listID.'/members';
$MailChimp -> post($newendpoint, [
'email_address' => 'newemail@example.com',
'status' => 'subscribed'
]);
$MailChimp -> patch($endpoint, [
'email_address' => 'newemail@example.com',
'status' => 'subscribed'
]);

--

--

--

A web developer and author living and working in Brighton, England. Everything I post on Medium is a copy — the originals are on my own website, adactio.com

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jeremy Keith

Jeremy Keith

A web developer and author living and working in Brighton, England. Everything I post on Medium is a copy — the originals are on my own website, adactio.com

More from Medium

How to Implement Symlink with Laravel Project in Shared Hosting (Alternate Storage: link)

Magento 2.4.4 Release: What’s New? — BroSolutions

An open-source platform for Enterprise eCommerce?

Web Development Using PHP Frameworks