How to check last inser email in mail chimp php

To check the last inserted email in Mailchimp using PHP, you can use the Mailchimp API. Here's an example of how you can do it:

Step 1: Get your Mailchimp API key

First, you need to get your Mailchimp API key. You can find it in your Mailchimp account settings under "Account" > "API keys".

Step 2: Install the Mailchimp PHP library

You can install the Mailchimp PHP library using Composer:

composer require mailchimp/mailchimp

Step 3: Initialize the Mailchimp API

Create a PHP file and initialize the Mailchimp API with your API key:

<?php

require 'vendor/autoload.php';

use Mailchimp\Mailchimp;

$api_key = 'your_api_key_here';
$mc = new Mailchimp($api_key);

?>

Step 4: Get the last inserted email

Use the lists/subscribe endpoint to get the last inserted email. You can specify the list ID and the status parameter to get the last inserted email:

$list_id = 'your_list_id_here';
$status = 'subscribed';

$response = $mc->get('lists/'. $list_id. '/members', array(
    'status' => $status,
    'count' => 1,
    'offset' => 0
));

$email = $response['members'][0]['email_address'];

echo $email; // Output: the last inserted email

In this example, we're using the lists/subscribe endpoint to get the last inserted email. We're specifying the list ID and the status parameter to get the last inserted email. We're also specifying the count parameter to get only one result, and the offset parameter to get the first result.

Note: Make sure to replace your_api_key_here and your_list_id_here with your actual Mailchimp API key and list ID.