• Resolved bojanpavlov

    (@bojanpavlov)


    Hi there,
    I was chatting with your support and was informed that there is a way to connect the contact form with the Mailpoet plugin. What I need is to have checkbox on the contact form which (if checked) will send information the mailpoet that user wants to get the newsletter.
    Hope that this is still possible.
    Best,
    Bojan

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi @bojanpavlov

    I hope you are doing good today.

    We have such a request and in the future, we will have integration with Mailpoet. However, at this point, there is no ETA when this will be implemented.
    Please stay tune with our roadmap:
    https://wpmudev.com/roadmap/

    When it comes to chat with our agent, I made a review and we have some custom solution but please note this was over a year ago and it could not work now due to a core update. Please let us know does that will help:

    1. In the first place you will need to add this as a mu-plugin to your site:

    add_action( 'forminator_custom_form_after_save_entry', function( $form_id, $response ) {
    	if ( '10' !== $form_id ) {
    		return;
    	}
    	
    	if ( $response && is_array( $response ) ) {
    		if ( ! empty( $response ) ) {
    			if ( $response['success'] ) {
    				if ( class_exists( \MailPoet\API\API::class ) && $_POST['checkbox-1'][0] === 'add-to-newsletter' ) {
    					$mailpoet_api = \MailPoet\API\API::MP('v1');
    			
    					// Change the list ID
    					$list_id = '4';
    					$mail = trim( $_POST['email-1'] );
    			
    					$email_exists = false;
    					$added_to_list = false;
    			
    					try {
    						$subscriber = $mailpoet_api->getSubscriber( $mail );
    						$email_exists = true;	
    					} catch (\Exception $e) {
    					}
    					
    					// Checking if subscriber exists.
    					if ( ! $email_exists ) {
    						try {
    							$subscriber_data = array(
    								'email' => $mail,
    							);
    			
    							$options = array(
    								'send_confirmation_email' => true,
    								'schedule_welcome_email' => true,
    								'skip_subscriber_notification' => false,
    							);
    			
    							$subscriber = $mailpoet_api->addSubscriber( $subscriber_data, array( $list_id ), $options );
    							$added_to_list = true;
    						} catch (\Exception $e) {
    						}
    					}
    			
    					// Check if member added to list.
    					if ( ! $added_to_list ) {
    						if ( ! empty( $subscriber['subscriptions'] ) ) {
    							foreach ( $subscriber['subscriptions'] as $list ) {
    								if ( $list['segment_id'] === $list_id ) {
    									$added_to_list = true;
    									break;
    								}
    							}
    						}
    					}
    			
    					// Subscriber was added earlier but not on any list.
    					if ( $email_exists && ! $added_to_list ) {
    						try {
    							$mailpoet_api->subscribeToList( $subscriber['id'], $list_id );
    							$added_to_list = true;
    						} catch (\Exception $e) {
    						}
    					}
    				}
    			}
    		}
    	}
    }, 999, 2 );

    Must Use Plugins

    2. Now let’s go through some important parts

    ’10’ !== $form_id – remember to change to form id
    $_POST[‘checkbox-1’][0] === ‘add-to-newsletter’ – checkboxes can different value – I’ve set mine as “add-to-newsletter”
    $list_id = ‘4’; – Mail Poet’s list ID
    $mail = trim( $_POST[’email-1′] ); – the email field – probably yours will be the same

    3. Here you can set the default user status – those are the default values from Mailpoet

    $options = array(
    	'send_confirmation_email' => true,
    	'schedule_welcome_email' => true,
    	'skip_subscriber_notification' => false,
    );

    If you would like to add name and surname – you would have to add it to $subscriber_data – you can read more about this here https://github.com/mailpoet/mailpoet/blob/master/doc/api_methods/AddSubscriber.md

    I hope this will be a good starting point.

    Kind Regards,
    Kris

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @bojanpavlov ,

    We haven’t heard from you for some time now, so it looks like you don’t have more questions for us.

    Feel free to re-open this ticket if needed.

    Kind regards
    Kasia

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Connect Forminator with Mailpoet’ is closed to new replies.