mailchimp integration on a custom footer

I want the user to be able to opt-in to a MailChimp newsletter within a custom footer, which one. of our clients has asked for. The client also uses MailChimp so we therefore cannot use anything like contactform-7 etc

The two images below will help explain. The user will type in their email address and will submit the email to subscribe to the newsletter. I repeat this is in a custom footer and I am trying to do this from a child theme

for the firsenter image description here

I tried following the MailChimp api documentation for adding a member to an existing list . This didn’t work. It caused the site to crash

I have seen some code here which has been useful since it allows me to pass information from my JS file to my functions.php file

However, I keep receiving the same error when I type in an email that passes the regex
‘Something went wrong, please try again’

I have checked the network tab on chrome and the email, a security token and the correct action are all showing – so information is being passed from JS to php. It also (weirdly) is showing a 200 code after submitting. However, there are no new subscribers showing on MailChimp and the error message above is showing (which if you look below is the default case in the subscribe_user_to_mailchimp function)

How can I resolve this?

Code is below:



edit: I printed the error message and got this in the response: