This documentation page is for Quform version 1 and may not be applicable for Quform 2 click here to visit the documentation for Quform 2.

Step 1

Install the Mailjet PHP API on your server. In this example we will install it in the wp-content folder. The API requires composer to install. You will need command line access to the server (e.g. via ssh) or you can use composer to install it locally on your PC and FTP upload the files.

You will need composer installed, go here if you do not have it.

In the command line change directory into the wp-content directory:

1
cd wp-content/
cd wp-content/

Then run this command to install the Mailjet PHP API:

1
composer require mailjet/mailjet-apiv3-php
composer require mailjet/mailjet-apiv3-php

Step 2

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

1
2
3
4
5678
9
10
11
12
1314
15
16
17
18
19
20
21
22
function my_mailjet_integration(iPhorm $form)
{
    require_once WP_CONTENT_DIR . '/vendor/autoload.php';
 
    $apikey = 'MJ_APIKEY_PUBLIC';    $apisecret = 'MJ_APIKEY_PRIVATE';    $listid = 1234; 
    $mj = new \Mailjet\Client($apikey, $apisecret);
    $response = $mj->post(\Mailjet\Resources::$ContactslistManagecontact, array(
        'id' => $listid,
        'body' => array(
            'Email' => $form->getValue('iphorm_1_1'),            'Action' => 'addforce'
        )
    ));
 
    if (defined('WP_DEBUG') && WP_DEBUG && !$response->success()) {
        iphorm_error_log($response->getStatus(), $response->getBody());
    }
}
add_filter('iphorm_post_process_1', 'my_mailjet_integration');
function my_mailjet_integration(iPhorm $form)
{
    require_once WP_CONTENT_DIR . '/vendor/autoload.php';

    $apikey = 'MJ_APIKEY_PUBLIC';
    $apisecret = 'MJ_APIKEY_PRIVATE';
    $listid = 1234;

    $mj = new \Mailjet\Client($apikey, $apisecret);
    $response = $mj->post(\Mailjet\Resources::$ContactslistManagecontact, array(
        'id' => $listid,
        'body' => array(
            'Email' => $form->getValue('iphorm_1_1'),
            'Action' => 'addforce'
        )
    ));

    if (defined('WP_DEBUG') && WP_DEBUG && !$response->success()) {
        iphorm_error_log($response->getStatus(), $response->getBody());
    }
}
add_filter('iphorm_post_process_1', 'my_mailjet_integration');
  • On lines 5 and 6, replace MJ_APIKEY_PUBLIC and MJ_APIKEY_PRIVATE with your API Key and Secret Key, you can get them in Mailjet at My account – REST API – Master API Key & Sub API key management
  • On line 7, replace the number 1234 with your list ID, which is visible on the Contacts page in Mailjet.
  • On line 13, replace iphorm_1_1 with the unique ID of the Email address element in the form.
  • On line 22, replace the number 1 with the form ID.

Troubleshooting

The code above will log an error to the error log if the insertion was unsuccessful and WP_DEBUG is true. If you are having issues then temporarily enable debug logging and check the log file to see what is wrong.

Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy