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

Tailwinds CSS, Jetstream and oh Baby, LIVEWIRE. Add-ons Overhall. Yaml and more

How To ‘Design’ a Design System — Part I

Magento 2 an Adobe Commerce Create PWA app in 5 minutes without PWA Studio and other single-page JS…

Powerlevel10k, Oh My Zsh & Tabby