Tutorials PHP How to Add Subscribers to a List Using MailChimp REST Api V3

How to Add Subscribers to a List Using MailChimp REST Api V3

MailChimp REST API V3 exposes methods that allow you to add, manage members of a specific MailChimp list. The following code snippet helps you to add a new subscriber to MailChimp List.

<?php
class ST_Newsletter_Plugin {
	public function __construct(){ 
	
	} 
	
	function subscribe($user_id, $user_email){
		//get api_key and list id from admin settings
		$api_key = "c8d8c17ae54aui8ujnj43343-us9";
		$list_id = "2d9e113i8hm";
		
		require_once('MailChimp.php');
		$mailChimp = new MailChimp($api_key);
		
		$result = $mailChimp->post("lists/$list_id/members", [
			'email_address' => $user_email,
			'status'=> 'subscribed'
		]);

		if ($mailChimp->success()) {
		    echo "success";
		} else {
		   echo "fail";
		}
	}
}

?>

You can download “MailChimp.php” from GitHub.

Total
0
Shares
guest
0 Comments
Inline Feedbacks
View all comments
Previous Post
Wordpress Tutorials

How to Register & Display Sidebars in WordPress

Next Post
Firebase Cloud Messaging

How to Integrate Firebase Cloud Messaging for Android

Related Posts
By clicking “Allow All”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts. Cookie Notice
Allow All
0
Would love your thoughts, please comment.x
()
x