Mailpoet Sign up on Custom registration form won't work
I've been trying to solve this myself for hours but I can't figure out where I am going wrong.
I have a custom registration form on my website and I would like to add a checkbox for users to sign up for the newsletter.
I went through the Mailpoet Docs and tried everything that they describe there but something is not working for me.
The user is being signed up successfully but never gets added to my mainling list. Here's my code
function newsletterSignUp(){
$subscriber_data = array(
'email' = sanitize_text_field($_POST['email']),
'first_name' = sanitize_text_field($_POST['first_name']),
'last_name' = sanitize_text_field($_POST['last_name'])
);
$list = \MailPoet\API\API::MP('v1')-getLists()[0][id];
//Returns the ID of the list that I want to assign subscribers to
try {
$subscriber = \MailPoet\API\API::MP('v1')-addSubscriber($subscriber_data, $list, $options);
} catch(Exception $exception) {
// return $exception-getMessage();
}
}
I am calling this function like this:
if(isset($_POST['submit'])){
// Some other code to sign up the user
if(isset($_POST['subscribe'])){ //The name of my checkbox input
newsletterSignUp();
}
}
Any help will be greatly appreciated!!
Topic newsletter api plugins Wordpress
Category Web