- Sendy is a self hosted newsletter application that enables you to send newsletters to your subscribers using Amazon SES, at a very low price.
In this article we are going to explain how to integrate Gravity Forms with Sendy using a simple function.
The function will automatically subscribe the email address submitted in the form to the Sendy newsletter list of your choice.
For this we are going to use the post_to_third_party function after form submission from Gravity Forms API.
First we will add an action that will tell the form what to do
add_action('gform_after_submission', 'post_to_third_party', 10, 2);
If you have multiple forms but want to integrate only one form with Sendy, the code needs to be changed
add_action('gform_after_submission_1', 'post_to_third_party', 10, 2);
where 1 is the ID of the form you want to integrate with Sendy.
After that we create our function
function post_to_third_party($entry, $form) { $post_url = 'http://your_sendy_url/subscribe'; $body = array( 'email' => $entry['2'], 'list' => 'your_list_ID' ); $request = new WP_Http(); $response = $request->post($post_url, array('body' => $body)); }
Now you just need to change the line for your sendy list url
$post_url = 'http://your_sendy_url/subscribe';
and the line that specifies the list ID where the user will be subscribed. You can find the list ID in Sendy, by viewing all your lists, the ID will be in the right of the list.
'list' => 'your_list_ID'
Below you can copy the whole function and paste it in your theme’s functions.php file.
add_action('gform_after_submission', 'post_to_third_party', 10, 2); function post_to_third_party($entry, $form) { $post_url = 'http://your_sendy_url/subscribe'; $body = array( 'email' => $entry['2'], 'list' => 'your_list_ID' ); $request = new WP_Http(); $response = $request->post($post_url, array('body' => $body)); }
Note that the above function will subscribe form submitters to Sendy automatically, so for this reason we suggest to enable Double Opt-In in your Sendy list to give the subscriber the option to confirm the subscription.