How To Connect WordPress and Emma Email Marketing API

emma

I had a recent project where I needed to create a custom email sign up form, and then send the data directly to the client’s Emma email marketing list. There are a few plugins available, but I needed full control of the sign up form.

Thankfully, Emma provides a simple API for connecting to their system.

The Form

First, I built out the form using basic fields for First Name, Last Name, and Email.

Next, I added a conditional to header.php of the theme to check if the email field had been submitted. If it had, then I ran the function to add the user to Emma and passed in the $_POST data. I also added a redirect, sending the user to a thank you page after they had been added to Emma.

if ( isset( $_POST['emma_email'] ) ) {

	add_user_to_emma( $_POST );
	wp_redirect( home_url() . '/thank-you/' );

}

The Emma API

Here is the add_user_to_emma function that does all the magic. Add this to your functions.php file, and remember to add in your own account details.

You’ll need a few details from your Emma account in order to connect to their API. You’ll need:

  • Your Account ID
  • Your Public API Key
  • Your Private API Key
  • The ID(s) of the group(s) you want to add the user to

Once you have that information, you can plug them into the function. Then you need to get the data for each field in your form and add it to the member_data array. This array is sent to Emma with the specific information about that user. You can add any custom fields you want to this array, as long as they can be mapped to a field in your Emma account.

Using a basic curl script, the function connects to the Emma account specified by the account ID. It also sends Emma the member_data array so that a new user can be created with the information submitted in the email signup form.

Conclusion

Using the Emma API makes it easy to create your own custom email sign up forms and send the data to your Emma account. It is also a great introduction to learning how third party APIs can be used in a WordPress theme. Check out the Emma API documentation for more information.

2 thoughts on “How To Connect WordPress and Emma Email Marketing API

  1. Jeremy you made my day!

    Had issues with both the Gravity Forms’ Emma addon and the other WordPress plugin for Emma integration. Then I found your post and everything now works smoothly!

    Thank you for sharing!

Leave a Reply

Your email address will not be published. Required fields are marked *