MailerLite

The Quform WordPress v2 documentation is not yet finished. Please post on the forums if you have any questions in the mean time.

Click here to visit the complete documentation for Quform 1.x

Optionally subscribe using a checkbox

Add the following code to your theme functions.php file (or create a plugin for it).

1
2
34
5
6
789
10
111213
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function my_mailerlite_integration(array $result, Quform_Form $form)
{
    if ($form->getElement('quform_1_5')->isEmpty()) {        return $result;
    }
 
    $apiKey = 'fc7b8c5b32067bcd47cafb5f475d2fe9';    $groupId = '3640549'; 
    $data = array(
        'email' => $form->getValueText('quform_1_4'),        'name' => $form->getValueText('quform_1_3')    );
 
    $curl = curl_init();
 
    curl_setopt_array($curl, array(
        CURLOPT_URL => sprintf('https://api.mailerlite.com/api/v2/groups/%s/subscribers', $groupId),
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_POSTFIELDS => wp_json_encode($data),
        CURLOPT_HTTPHEADER => array(
            'content-type: application/json',
            sprintf('x-mailerlite-apikey: %s', $apiKey)
        ),
    ));
 
    $response = curl_exec($curl);
    $err = curl_error($curl);
 
    curl_close($curl);
 
    if (defined('WP_DEBUG') && WP_DEBUG) {
        if ($err) {
            Quform::log('cURL Error:' . $err);
        } else {
            $response = json_decode($response, true);
 
            if (isset($response['error'])) {
                Quform::log('MailerLite Error:', $response['error']);
            }
        }
    }
 
    return $result;
}
add_filter('quform_post_process_1', 'my_mailerlite_integration', 10, 2);
function my_mailerlite_integration(array $result, Quform_Form $form)
{
    if ($form->getElement('quform_1_5')->isEmpty()) {
        return $result;
    }

    $apiKey = 'fc7b8c5b32067bcd47cafb5f475d2fe9';
    $groupId = '3640549';

    $data = array(
        'email' => $form->getValueText('quform_1_4'),
        'name' => $form->getValueText('quform_1_3')
    );

    $curl = curl_init();

    curl_setopt_array($curl, array(
        CURLOPT_URL => sprintf('https://api.mailerlite.com/api/v2/groups/%s/subscribers', $groupId),
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_POSTFIELDS => wp_json_encode($data),
        CURLOPT_HTTPHEADER => array(
            'content-type: application/json',
            sprintf('x-mailerlite-apikey: %s', $apiKey)
        ),
    ));

    $response = curl_exec($curl);
    $err = curl_error($curl);

    curl_close($curl);

    if (defined('WP_DEBUG') && WP_DEBUG) {
        if ($err) {
            Quform::log('cURL Error:' . $err);
        } else {
            $response = json_decode($response, true);

            if (isset($response['error'])) {
                Quform::log('MailerLite Error:', $response['error']);
            }
        }
    }

    return $result;
}
add_filter('quform_post_process_1', 'my_mailerlite_integration', 10, 2);
  • On line 3, replace 1_5 with the Checkbox element unique ID
  • On line 7, replace fc7b8c5b32067bcd47cafb5f475d2fe9 with your MailerLite API Key, which you can find on this page
  • On line 8, replace 3640549 with your MailerLite Group ID, which you can find on this page under Subscriber groups
  • On line 11, replace 1_4 with the Email element unique ID
  • On line 12, replace 1_3 with the Name element unique ID
  • On line 51, replace the number 1 with the form ID

Always subscribe

Add the following code to your theme functions.php file (or create a plugin for it).

1
2
345
6
789
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function my_mailerlite_integration(array $result, Quform_Form $form)
{
    $apiKey = 'fc7b8c5b32067bcd47cafb5f475d2fe9';    $groupId = '3640549'; 
    $data = array(
        'email' => $form->getValueText('quform_1_4'),        'name' => $form->getValueText('quform_1_3')    );
 
    $curl = curl_init();
 
    curl_setopt_array($curl, array(
        CURLOPT_URL => sprintf('https://api.mailerlite.com/api/v2/groups/%s/subscribers', $groupId),
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_POSTFIELDS => wp_json_encode($data),
        CURLOPT_HTTPHEADER => array(
            'content-type: application/json',
            sprintf('x-mailerlite-apikey: %s', $apiKey)
        ),
    ));
 
    $response = curl_exec($curl);
    $err = curl_error($curl);
 
    curl_close($curl);
 
    if (defined('WP_DEBUG') && WP_DEBUG) {
        if ($err) {
            Quform::log('cURL Error:' . $err);
        } else {
            $response = json_decode($response, true);
 
            if (isset($response['error'])) {
                Quform::log('MailerLite Error:', $response['error']);
            }
        }
    }
 
    return $result;
}
add_filter('quform_post_process_1', 'my_mailerlite_integration', 10, 2);
function my_mailerlite_integration(array $result, Quform_Form $form)
{
    $apiKey = 'fc7b8c5b32067bcd47cafb5f475d2fe9';
    $groupId = '3640549';

    $data = array(
        'email' => $form->getValueText('quform_1_4'),
        'name' => $form->getValueText('quform_1_3')
    );

    $curl = curl_init();

    curl_setopt_array($curl, array(
        CURLOPT_URL => sprintf('https://api.mailerlite.com/api/v2/groups/%s/subscribers', $groupId),
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_POSTFIELDS => wp_json_encode($data),
        CURLOPT_HTTPHEADER => array(
            'content-type: application/json',
            sprintf('x-mailerlite-apikey: %s', $apiKey)
        ),
    ));

    $response = curl_exec($curl);
    $err = curl_error($curl);

    curl_close($curl);

    if (defined('WP_DEBUG') && WP_DEBUG) {
        if ($err) {
            Quform::log('cURL Error:' . $err);
        } else {
            $response = json_decode($response, true);

            if (isset($response['error'])) {
                Quform::log('MailerLite Error:', $response['error']);
            }
        }
    }

    return $result;
}
add_filter('quform_post_process_1', 'my_mailerlite_integration', 10, 2);
  • On line 3, replace fc7b8c5b32067bcd47cafb5f475d2fe9 with your MailerLite API Key, which you can find on this page
  • On line 4, replace 3640549 with your MailerLite Group ID, which you can find on this page under Subscriber groups
  • On line 7, replace 1_4 with the Email element unique ID
  • On line 8, replace 1_3 with the Name element unique ID
  • On line 47, replace the number 1 with the form ID

Troubleshooting

If the integration is not working you can debug the issue by temporarily enabling debug logging. The cause of the issue should be logged to the wp-content/debug.log file.

Still having trouble? Head over to the forums.

Forums