Turnstile with WordPress and the Divi theme:

Protecting your WordPress website from spam and automated abuse is essential — but traditional CAPTCHA systems often frustrate real users and slow down your site. Cloudflare’s Turnstile offers a modern, privacy-first alternative that automatically distinguishes humans from bots without intrusive image puzzles or data tracking.

In this guide, we’ll walk through the complete process of integrating Cloudflare Turnstile with WordPress, specifically using the Divi theme. You’ll learn how to obtain your site and secret keys, configure validation in WordPress forms, and seamlessly embed Turnstile within Divi’s visual builder — all while keeping performance fast and user experience effortless.

By the end, you’ll have a secure, lightweight, and user-friendly verification layer that enhances both security and accessibility on your Divi-powered WordPress site.
You can of course use other themes that DIVI. More about that further down this article.

Setting up Maian Responder with CloudFlare Turnstile (Invisible)

Benefits of Cloudflare Turnstile

Privacy-friendly:
Turnstile doesn’t track users or use cookies — no data sent to Google.

Frictionless for users:
Usually invisible, with no “click all the traffic lights” puzzles.

Lightweight & fast:
Smaller script size → faster page loads.

Free with no usage limits:
No enterprise tiers or quotas — full features for all users.

Easy integration:
Simple API compatible with existing CAPTCHA flows.

Works without JavaScript or cookies (gracefully degrades):
Better accessibility and performance for all users.

To make things a little harder for myself—and to show that this method works — I chose a cross-domain setup. This means the signup form is on one URL (my main site, e.g., davidholywood.com), but the processing and validation are handled by Maian Responder hosted on a separate domain.

I use an old domain, make-it-count.dk, for hosting my Maian Responder instances. I run several subdomains for different projects, structured like this:

test.make-it-count.dk (The specific subdomain processing the form)

dfwd.make-it-count.dk

thepassionblogger.make-it-count.dk

etc…

 

(If you have the paid version of Maian Responder, you don’t actually have to run multiple installations. Maian Responder can easily handle multiple campaigns internally. Btw, I use the paid version, but the free version works fine if you have fewer than 1000 subscribers and only need one campaign with a set of automated emails.)

Cloudflare Turnstile Setup: Connecting the Domains
First, I logged into Cloudflare to get the security keys and settings configured.

From the Cloudflare menu, I chose Application Security / Turnstile. I then clicked Add site to create a new widget, which I named “Make-it-count”.

The next part is absolutely vital for a cross-domain setup like ours. We are using one form domain (davidholywood.com) and one validation domain (test.make-it-count.dk), so we must link them to a single widget.

The Hostname Allowed List
After you create the widget, go into its settings. Find the section called “Hostname management” (or just “Hostnames”). This is your allowed list.

You MUST add both domains here:

The domain hosting the form: davidholywood.com

The domain hosting the processing script: test.make-it-count.dk

This tells Cloudflare that both domains are authorized to use this specific Site Key and Secret Key pair. If you try to create two separate widgets, the keys will not work together. Using one widget with two hostnames is the correct approach.

Retrieving and Fixing the Code
On this same settings page, you will retrieve your Site Key (for the HTML form) and your Secret Key (for the PHP validation script). You’ll also see links to the Client-side integration code and Server-side integration code.

The code provided on these documentation pages is often set up for basic, single-domain integration and can be confusing. Even as an experienced developer, I ran into issues, which is why I wrote this article—to provide a reliable, working solution.

1. Server-Side Integration (The Fix)
Let’s start with the server part, which requires editing the signup.php file from the Maian Responder root directory. Unfortunately, the server-side code provided by the Cloudflare documentation can be buggy or incomplete for our specific needs.

Here is the part of the code we will focus on for the validation logic. This is the section that requires correction to ensure the validation check passes:

// Usage
$secret_key = ‘your-secret-key’;
$token = $_POST[‘cf-turnstile-response’] ?? ”;
$remoteip = $\_SERVER[‘HTTP_CF_CONNECTING_IP’] ??
$\_SERVER[‘HTTP_X_FORWARDED_FOR’] ??
$\_SERVER[‘REMOTE_ADDR’];

 

$\_SERVER won’t work. It is a blatant error. In my code I change $\_SERVER to $_SERVER (no slash) because a \ in a variable is invalid synthax and WILL fail.

 

Here is the correct code where I also inserted a DIE if the validation fails. No need to run the rest of the code if a bot signed up:

 

//—————————————————
// Cloudflare Turnstile START
//—————————————————
function validateTurnstile($token, $secret, $remoteip = null) {
    $url = ‘https://challenges.cloudflare.com/turnstile/v0/siteverify’;
    $data = [
        ‘secret’ => $secret,
        ‘response’ => $token
    ];
    if ($remoteip) {
        $data[‘remoteip’] = $remoteip;
    }
    $options = [
        ‘http’ => [
            ‘header’ => “Content-type: application/x-www-form-urlencoded\r\n”,
            ‘method’ => ‘POST’,
            ‘content’ => http_build_query($data)
        ]
    ];
    $context = stream_context_create($options);
    $response = file_get_contents($url, false, $context);
    if ($response === FALSE) {
        return [‘success’ => false, ‘error-codes’ => [‘internal-error’]];
    }
    return json_decode($response, true);
}
// Usage
$secret_key = ‘ENTER YOUR SECRET KEY HERE’;
$token = $_POST[‘cf-turnstile-response’] ?? ”;
$remoteip = $_SERVER[‘HTTP_CF_CONNECTING_IP’] ??
$_SERVER[‘HTTP_X_FORWARDED_FOR’] ??
$_SERVER[‘REMOTE_ADDR’];
$validation = validateTurnstile($token, $secret_key, $remoteip);
if ($validation[‘success’]) {
    // Valid token – process form
    // Note: We remove the echo “Form submission successful!”; here
    // as the script will continue to the main subscription flow below.
// So do nothing!
} else {
    // Invalid token – show error
    echo “Verification failed. Please try again.”;
    error_log(‘Turnstile validation failed: ‘ . implode(‘, ‘, $validation[‘error-codes’]));
    // The script must stop here!
    die();

}

//—————————————————
// Cloudflare Turnstile START
//—————————————————

And here you can see where in the signup.php you need to insert it – MAKE SURE YOU CREATE A BACKUP OF SIGNUP.PHP BEFORE YOU START EDITING – JUST IN CASE!

<?php
session_start();
/* SIGNUP OPS
———————————-*/
define(‘PATH’, __dir__ . ‘/’);
define(‘PARENT’, 1);
//—————————————————
// Error reporting
//—————————————————
include(PATH . ‘control/system/constants.php’);
if (version_compare(PHP_VERSION, ‘8.0.0’) >= 0) {
  include(PATH . ‘control/lib/tracy/vendor/tracy/tracy/src/tracy.php’);
}
use Tracy\Debugger;
if (version_compare(PHP_VERSION, ‘8.0.0’) >= 0) {
  // For development, report everything and enable tracy bar
  Debugger::$showBar = (defined(‘DEVELOPMENT_ENV’) ? true : false);
  Debugger::$strictMode = (defined(‘DEVELOPMENT_ENV’) ? true : false);
  Debugger::$errorTemplate = PATH . ‘control/lib/tracy/500.php’;
  Debugger::enable((defined(‘DEVELOPMENT_ENV’) ? Debugger::DEVELOPMENT : Debugger::PRODUCTION), PATH . ‘logs’);
}
//—————————————————
// Load files
//—————————————————
include(PATH . ‘control/’ . (file_exists(PATH . ‘control/user-options.php’) ? ‘user-‘ : ”) . ‘options.php’);
include(PATH . ‘content/language/global.php’);
include(PATH . ‘content/language/subscribe.php’);
include(PATH . ‘content/language/messages.php’);
include(PATH . ‘content/language/v1.4.php’);
include(PATH . ‘content/language/v2.1.php’);
include(PATH . ‘content/language/v2.2.php’);
include(PATH . ‘content/language/v2.3.php’);
include(PATH . ‘control/functions.php’);
//—————————————————
// Database connection
//—————————————————
if(file_exists(PATH . ‘control/_cfg.php’)){include(PATH . ‘control/_cfg.php’);}else{die(‘File “control/_cfg.php” is missing, please see installation instructions.’);}
include(PATH . ‘control/classes/class.db.php’);
$DB = new db();
$DB->db_conn();
//—————————————————
// Load class files
//—————————————————
mswFLCTR();
include(PATH . ‘control/system/core/mm.php’);
include(PATH . ‘control/classes/class.session.php’);
include(PATH . ‘control/classes/class.tags.php’);
include(PATH . ‘control/classes/mailer/class.mail.php’);
include(PATH . ‘control/classes/class.subscribe.php’);
include(PATH . ‘control/classes/class.autoresponders.php’);
include(PATH . ‘control/classes/class.logs.php’);
include(PATH . ‘control/classes/class.json.php’);
include(PATH . ‘control/classes/class.cleantalk.php’);
//—————————————————
// Load settings
//—————————————————
$SSN = new sessHandlr();
$Q   = $DB->db_query(“SELECT * FROM `” . DB_PREFIX . “settings` LIMIT 1”, true);
if ($Q == ‘err’) {
  header(“Location: install/index.php”);
  exit;
}
$SETTINGS = $DB->db_object($Q);
if (!isset($SETTINGS->id)) {
  header(“Location: ../install/index.php”);
  exit;
}
mswMemAllocation($SETTINGS);
$logging = ($SETTINGS->logging ? unserialize($SETTINGS->logging) : []);
 
 
 
//—————————————————
// Cloudflare Turnstile START
//—————————————————
function validateTurnstile($token, $secret, $remoteip = null) {
    $url = ‘https://challenges.cloudflare.com/turnstile/v0/siteverify’;
    $data = [
        ‘secret’ => $secret,
        ‘response’ => $token
    ];
    if ($remoteip) {
        $data[‘remoteip’] = $remoteip;
    }
    $options = [
        ‘http’ => [
            ‘header’ => “Content-type: application/x-www-form-urlencoded\r\n”,
            ‘method’ => ‘POST’,
            ‘content’ => http_build_query($data)
        ]
    ];
    $context = stream_context_create($options);
    $response = file_get_contents($url, false, $context);
    if ($response === FALSE) {
        return [‘success’ => false, ‘error-codes’ => [‘internal-error’]];
    }
    return json_decode($response, true);
}
// Usage
$secret_key = ‘ENTER YOUR SECRET KEY HERE’;
$token = $_POST[‘cf-turnstile-response’] ?? ”;
$remoteip = $_SERVER[‘HTTP_CF_CONNECTING_IP’] ??
$_SERVER[‘HTTP_X_FORWARDED_FOR’] ??
$_SERVER[‘REMOTE_ADDR’];
$validation = validateTurnstile($token, $secret_key, $remoteip);
if ($validation[‘success’]) {
    // Valid token – process form
    // Note: We remove the echo “Form submission successful!”; here
    // as the script will continue to the main subscription flow below.
// So do nothing!
} else {
    // Invalid token – show error
    echo “Verification failed. Please try again.”;
    error_log(‘Turnstile validation failed: ‘ . implode(‘, ‘, $validation[‘error-codes’]));
    // The script must stop here!
    die();
}
//—————————————————
// Cloudflare Turnstile END
//—————————————————
 
 
 
//—————————————————
// Set session var for CleanTalk
//—————————————————
$SSN->set(array(‘stime’ => time()));
//—————————————————
// Declare and initialise
//—————————————————
$msgConfig       = array(
  ‘file’ => LOG_FILE_SUBSCRIBE,
  ‘folder’ => LOGS_FOLDER,
  ‘trans-method’ => ‘ajax’
);
$report          = [];
$resp            = array(
  ‘fail’,
  $subscribeLang[3]
);
$LOGS            = new logRoutines((in_array(‘sub’, $logging) ? ‘yes’ : ‘no’), $msgConfig[‘folder’], $gblang, $SETTINGS);
$SUB             = new mrSubRoutines();
$JSON            = new jsonHandler();
$MRMSG           = new mrAutoResponders();
$CTALK           = new cleanTalk();
$MRMSG->msgType  = ‘message’;
$MRMSG->settings = $SETTINGS;
$MRMSG->daylimit = ‘m-daily’;
$CTALK->settings = $SETTINGS;
$CTALK->ssn      = $SSN;
//—————————————————
// Set timezone / timestamp
//—————————————————
mswSetTimeZone($SETTINGS->timezone);
//—————————————————
// Start signup routine, check method
//—————————————————
// Ajax method..(default)..
if (isset($_POST[‘camp’])) {
  $_GET[‘camp’] = mswDigit($_POST[‘camp’]);
  $LOGS->write($subscribeLang[29], $msgConfig[‘file’]);
}
// Ajax method..Proxy..
if (!in_array($msgConfig[‘trans-method’], array(‘post’,’get’))) {
  if (!isset($_GET[‘cid’], $_GET[’em’])) {
    $_POST[’em’] = (isset($_GET[’em’]) ? $_GET[’em’] : (isset($_POST[’em’]) ? $_POST[’em’] : ”));
    $_POST[‘nm’] = (isset($_GET[‘nm’]) ? $_GET[‘nm’] : (isset($_POST[‘nm’]) ? $_POST[‘nm’] : ”));
    $_POST[‘nm2’] = (isset($_GET[‘nm2’]) ? $_GET[‘nm2’] : (isset($_POST[‘nm2’]) ? $_POST[‘nm2’] : ”));
    // For CleanTalk..
    if ($SETTINGS->ctenable == ‘yes’ && $SETTINGS->ctapi) {
      $_POST[‘ct_ts’] = date(‘Y’);
    }
  }
}
// POST method..
if (isset($_POST[‘mthd’], $_POST[‘cid’])) {
  $_GET[‘camp’] = mswDigit($_POST[‘cid’]);
  $msgConfig[‘trans-method’] = ‘post’;
  $LOGS->write($signup1_4[6], $msgConfig[‘file’]);
}
// GET method..
if (isset($_GET[‘mthd’], $_GET[‘cid’])) {
  $_GET[‘camp’] = mswDigit($_GET[‘cid’]);
  $_POST[‘nm’] = (isset($_GET[‘nm’]) ? $_GET[‘nm’] : ”);
  $_POST[‘nm2’] = (isset($_GET[‘nm2’]) ? $_GET[‘nm2’] : ”);
  $_POST[’em’] = (isset($_GET[’em’]) ? $_GET[’em’] : ”);
  $msgConfig[‘trans-method’] = ‘get’;
  $LOGS->write($signup1_4[7], $msgConfig[‘file’]);
}
//—————————————————
// Resend verification email
//—————————————————
if (isset($_GET[‘rsd’])) {
  $DIR       = $gblang[1];
  $LANG      = $gblang[2];
  $CHARSET   = $gblang[0];
  $LANG      = $meta[0];
  $DIR       = $meta[1];
  $TITLE     = ”;
  $HEAD_TEXT = ”;
  $BODY_TEXT = ”;
  if (ctype_alnum($_GET[‘rsd’]) || ctype_digit($_GET[‘rsd’])) {
    $LOGS->write(str_replace(‘{var}’, $_GET[‘rsd’], $subscribeLang[31]), $msgConfig[‘file’]);
    // Get subscriber
    $subscriber = $SUB->getSubscriber($_GET[‘rsd’]);
    if (isset($subscriber[‘id’])) {
      $LOGS->write(str_replace(array(
        ‘{var}’,
        ‘{name}’,
        ‘{email}’
      ), array(
        $_GET[‘rsd’],
        $subscriber[‘name’] . ‘ ‘ . $subscriber[‘name2’],
        $subscriber[’email’]
      ), $subscribeLang[32]), $msgConfig[‘file’]);
      // Get campaign..
      $campaign = $SUB->getCampaign($subscriber[‘system’]);
      // Resend..
      if (isset($campaign[‘name’])) {
        $smtp                  = [];
        $smtp[‘mailpref’]      = ($campaign[‘smtp_host’] ? $campaign[‘mailpref’] : $SETTINGS->mailpref);
        $smtp[‘smtp_host’]     = ($campaign[‘smtp_host’] ? $campaign[‘smtp_host’] : $SETTINGS->smtp_host);
        $smtp[‘smtp_port’]     = ($campaign[‘smtp_host’] ? $campaign[‘smtp_port’] : $SETTINGS->smtp_port);
        $smtp[‘smtp_user’]     = ($campaign[‘smtp_host’] ? $campaign[‘smtp_user’] : $SETTINGS->smtp_user);
        $smtp[‘smtp_pass’]     = ($campaign[‘smtp_host’] ? $campaign[‘smtp_pass’] : $SETTINGS->smtp_pass);
        $smtp[‘smtp_security’] = ($campaign[‘smtp_host’] ? $campaign[‘smtp_security’] : $SETTINGS->smtp_security);
        $smtp[‘smtp_insec’]    = ($campaign[‘smtp_host’] ? $campaign[‘smtp_insec’] : $SETTINGS->smtp_insec);
        $mrMail                = new mailingSystem($smtp, [], [], $SETTINGS);
        $f_r                   = array(
          ‘{campaign}’ => $campaign[‘name’],
          ‘{name}’ => $subscriber[‘name’] . ‘ ‘ . $subscriber[‘name2’],
          ‘{first_name}’ => $subscriber[‘name’],
          ‘{last_name}’ => $subscriber[‘name2’],
          ‘{url}’ => $SETTINGS->protocol . ‘://’ . $SETTINGS->rootpath . ‘/’ . SUBSCRIBE_PROCESSOR . ‘?v=’ . $subscriber[‘code’],
          ‘{website}’ => $campaign[‘website’],
          ‘{website_name}’ => $campaign[‘homepage’]
        );
        $msg                   = strtr(mswTmp(PATH . ‘content/language/email-templates/email-verification.txt’), $f_r);
        $LOGS->write(str_replace(array(
          ‘{name}’,
          ‘{subject}’
        ), array(
          $subscriber[‘name’] . ‘ ‘ . $subscriber[‘name2’],
          $subscribeEmailLang[0]
        ), $subscribeLang[10]) . ‘:’ . mswNL() . $msg, $msgConfig[‘file’]);
        try {
          $mrMail->sendMail(array(
            ‘to_name’ => $subscriber[‘name’] . ‘ ‘ . $subscriber[‘name2’],
            ‘to_email’ => $subscriber[’email’],
            ‘from_name’ => $campaign[‘from_name’],
            ‘from_email’ => $campaign[‘from_email’],
            ‘subject’ => $subscribeEmailLang[0],
            ‘wrapper’ => ($campaign[‘wrapper’] && file_exists(PATH . ‘content/language/email-templates/wrappers/’ . $campaign[‘wrapper’]) ? $campaign[‘wrapper’] : ”),
            ‘msg’ => $mrMail->htmlWrapper(array(
              ‘charset’ => $gblang[0],
              ‘lang’ => $meta[0],
              ‘dir’ => $meta[1],
              ‘title’ => $subscribeEmailLang[0],
              ‘header’ => $subscribeEmailLang[0],
              ‘content’ => mswL2BR($msg),
              ‘footer’ => (LICENCE_VER == ‘locked’ ? ” : $gblang[29])
            )),
            ‘reply-to’ => $campaign[‘reply_to’],
            ‘plain’ => $msg,
            ‘htmlWrap’ => ‘yes’
          ), $gblang);
        } catch(Exception $e) {
          $LOGS->write($e->getMessage(), $msgConfig[‘file’]);
        }
        if (MAIL_ACTIVATE) {
          $mrMail->smtpClose();
        }
        // Display success template..
        $TITLE     = $subscribeLang[34];
        $HEAD_TEXT = $subscribeLang[34];
        $BODY_TEXT = $subscribeLang[33];
        $TMP       = ‘resend-success.php’;
      }
    }
  }
  include(PATH . ‘content/’ . (isset($TMP) && file_exists(PATH . ‘content/’ . $TMP) ? $TMP : ‘resend-error.php’));
  exit;
}
if (!isset($_GET[‘v’]) && isset($_POST[‘nm’], $_POST[’em’], $_GET[‘camp’]) && $_GET[‘camp’] > 0) {
  // Error check for get, post methods..
  if (in_array($msgConfig[‘trans-method’], array(‘post’,’get’))) {
    $errs = [];
    if ($_POST[‘nm’] == ”) {
      $errs[] = $signup1_4[2];
    }
    if (isset($_POST[‘nm2’]) && $_POST[‘nm2’] == ”) {
      $errs[] = $signup1_4[3];
    }
    if (!mswEm($_POST[’em’])) {
      $errs[] = $signup1_4[4];
    }
    if (!empty($errs)) {
      $DIR       = $gblang[1];
      $LANG      = $gblang[2];
      $CHARSET   = $gblang[0];
      $LANG      = $meta[0];
      $DIR       = $meta[1];
      $TITLE     = $signup1_4[1];
      $HEAD_TEXT = $signup1_4[1];
      $BODY_TEXT = str_replace(‘{errors}’, implode(‘<br>’, $errs), $signup1_4[5]);
      $BACK_TEXT = $signup1_4[0];
      include(PATH . ‘content/signup-error.php’);
      $LOGS->write(count($errs) . ‘ Error(s): ‘ . implode(mswNL(), $errs), $msgConfig[‘file’]);
      exit;
    }
  }
  // Vars..
  $email = $_POST[’em’];
  if (!isset($_POST[‘nm2’])) {
    $name   = $SUB->surName($_POST[‘nm’]);
    $name2  = $SUB->surName($_POST[‘nm’], ‘last’);
  } else {
    $name   = $_POST[‘nm’];
    $name2  = $_POST[‘nm2’];
  }
  $campID = mswDigit($_GET[‘camp’]);
  $custom = [];
  $LOGS->write(str_replace(‘{method}’, strtoupper($msgConfig[‘trans-method’]), $subscribeLang[0]), $msgConfig[‘file’]);
  if (!empty($_POST)) {
    $LOGS->write(‘POST VARS: ‘ . mswNL() . print_r($_POST, true), $msgConfig[‘file’]);
  }
  if (!empty($_GET)) {
    $LOGS->write(‘GET VARS: ‘ . mswNL() . print_r($_GET, true), $msgConfig[‘file’]);
  }
  $LOGS->write(str_replace(array(
    ‘{name}’,
    ‘{email}’,
    ‘{campaign}’
  ), array(
    $name . ‘ ‘ . $name2,
    $_POST[’em’],
    $_GET[‘camp’]
  ), $subscribeLang[1]), $msgConfig[‘file’]);
  // Is cleantalk enabled?
  $spamBot = ‘no’;
  if ($SETTINGS->ctenable == ‘yes’ && $SETTINGS->ctapi) {
    $CTALK->transmeth = $msgConfig[‘trans-method’];
    $ctk_user = $CTALK->check(array(
      ’email’ => $email,
      ‘name’ => $name . ‘ ‘ . $name2
    ));
    if (!isset($ctk_user[‘allow’]) || $ctk_user[‘allow’] == 0) {
      $spamBot = ‘yes’;
    }
  }
  // Check name fields are ok..
  if ($name && $name2 && $spamBot == ‘no’) {
    //——————————————————————–
    // Check blacklist
    //——————————————————————–
    $black = array(‘fail’, array($email));
    if (mswEm($_POST[’em’])) {
      $black = $SUB->blackListed($email);
    }
    //——————————————————————–
    // Check if email and campaign ID are valid
    //——————————————————————–
    if ($black[0] == ‘no’) {
      if (mswEm($email)) {
        // Is campaign valid?
        $campaign = $SUB->getCampaign($campID);
        if (isset($campaign[‘id’])) {
          // Custom tags..
          $customTags = $MRMSG->tags();
          // Delete logic for duplicates
          // Check if email address is already signed up for this campaign
          switch($SETTINGS->duplicates) {
            case ‘yes’:
              $doesSubExist = $SUB->checkEmailCampaign($email, $campID, ‘yes’);
              $LOGS->write($signup1_4[10], $msgConfig[‘file’]);
              break;
            case ‘del’:
              $doesSubExist = $SUB->checkEmailCampaign($email, $campID, ‘yes’);
              $LOGS->write($signup1_4[11], $msgConfig[‘file’]);
              $SUB->remove($email, $campID, ‘yes’);
              break;
            case ‘no’:
              $doesSubExist = $SUB->checkEmailCampaign($email, $campID);
              $LOGS->write($signup1_4[9], $msgConfig[‘file’]);
              break;
          }
          if ($doesSubExist[‘status’] == ‘no’) {
            $LOGS->write($subscribeLang[9] . ‘ ‘ . ucfirst($campaign[‘opt_level’]), $msgConfig[‘file’]);
            // Process based on opt in level
            switch ($campaign[‘opt_level’]) {
              // For single opt in, we just add email and send confirmation / messages
              case ‘single’:
                $uniCode = ”;
                $enabled = ‘yes’;
                break;
              // For double, email needs verifying first
              default:
                $uniCode = $SUB->getCode(20);
                $enabled = ‘no’;
                break;
            }
            // Is there custom field data to capture?
            foreach (array_merge($_POST, $_GET) AS $pK => $pV) {
              if (!in_array($pK, array(
                ‘nm’,
                ‘nm2’,
                ‘mthd’,
                ‘cid’,
                ’em’,
                ‘camp’,
                ‘callback’,
                ‘_’,
                ‘url’
              ))) {
                // Check data from remote site..
                if (!is_array($pV) && substr($pK, 0, 6) == ‘mrcus_’) {
                  $custom[] = substr($pK, 6) . ‘ = ‘ . $pV;
                } else {
                  if (is_array($pV)) {
                    foreach ($pV AS $pK2 => $pV2) {
                      $custom[] = $pK2 . ‘ = ‘ . $pV2;
                    }
                  } else {
                    $custom[] = $pK . ‘ = ‘ . $pV;
                  }
                }
              }
            }
            //—————————–
            // Add subscriber
            //—————————–
            $id = $SUB->addSubscriber(array(
              ‘name’ => $name,
              ‘name2’ => $name2,
              ’email’ => $email,
              ‘ip’ => mswIP(),
              ‘enabled’ => $enabled,
              ‘code’ => $uniCode,
              ‘camp’ => $campID,
              ‘custom’ => (!empty($custom) ? implode(mswNL(), $custom) : ”)
            ));
            // Send emails
            switch ($enabled) {
              case ‘yes’:
                // Send campaign emails if set to send immediately after subscription
                $cmpMessages = $SUB->initialCampaignMessages($campID);
                if (!empty($cmpMessages)) {
                  $LOGS->write(str_replace(‘{count}’, count($cmpMessages), $subscribeLang[24]), $msgConfig[‘file’]);
                  //—————————————————
                  // Get SMTP settings for campaign
                  // If host isn`t set, we use main settings
                  //—————————————————
                  $smtp = array(
                    ‘mailpref’  => ($campaign[‘smtp_host’] ? $campaign[‘mailpref’] : $SETTINGS->mailpref),
                    ‘smtp_host’ => ($campaign[‘smtp_host’] ? $campaign[‘smtp_host’] : $SETTINGS->smtp_host),
                    ‘smtp_port’ => ($campaign[‘smtp_host’] ? $campaign[‘smtp_port’] : $SETTINGS->smtp_port),
                    ‘smtp_user’ => ($campaign[‘smtp_host’] ? $campaign[‘smtp_user’] : $SETTINGS->smtp_user),
                    ‘smtp_pass’ => ($campaign[‘smtp_host’] ? $campaign[‘smtp_pass’] : $SETTINGS->smtp_pass),
                    ‘smtp_security’ => ($campaign[‘smtp_host’] ? $campaign[‘smtp_security’] : $SETTINGS->smtp_security),
                    ‘smtp_insec’ => ($campaign[‘smtp_host’] ? $campaign[‘smtp_insec’] : $SETTINGS->smtp_insec),
                    ‘alive’ => ‘yes’
                  );
                  //——————————————————————–
                  // For security, mask password so it doesn`t appear in log file
                  //——————————————————————–
                  $smtpLog              = $smtp;
                  $smtpLog[‘smtp_pass’] = $glmsglang[1];
                  $LOGS->write($fulang[12] . ‘ ‘ . $campID . mswNL(2) . print_r($smtpLog, true), $msgConfig[‘file’]);
                  //—————————————————
                  // Build mail tags
                  //—————————————————
                  $mTags = array(
                    ‘%first_name%’ => $name,
                    ‘%last_name%’ => $name2,
                    ‘%name%’ => $name . ‘ ‘ . $name2,
                    ‘%email%’ => $email,
                    ‘%date_joined%’ => date($SETTINGS->dateformat, time()),
                    ‘%ip%’ => mswIP(),
                    ‘%unsubscribe%’ => $SETTINGS->protocol . ‘://’ . $SETTINGS->rootpath . ‘/’ . str_replace(‘{email}’, ($campaign[‘splash’] == ‘yes’ ? ‘cf_’ : ”) . mswEncrypt($id . $email) . ‘-‘ . $campID, UNSUB_LINK)
                  );
                  //—————————————————
                  // Custom Tags
                  //—————————————————
                  if (!empty($customTags)) {
                    $mTags = array_merge($mTags, $customTags);
                  }
                  foreach ($cmpMessages AS $cMSG => $cMSGData) {
                    $linkTrackPlainTags = $MRMSG->linkTags($cMSGData[‘plain_text’]);
                    $linkTrackHTMLTags = $MRMSG->linkTags($cMSGData[‘html_text’], ‘html’);
                    if (!empty($linkTrackPlainTags)) {
                      $cMSGData[‘plain_text’] = strtr($cMSGData[‘plain_text’], $linkTrackPlainTags);
                    }
                    if (!empty($linkTrackHTMLTags)) {
                      $cMSGData[‘html_text’] = strtr($cMSGData[‘html_text’], $linkTrackHTMLTags);
                    }
                    $markEmails  = array(
                      “‘{$email}'”
                    );
                    $attachments = array(
                      0,
                      0
                    );
                    $headers     = [];
                    $repeats     = array(
                      ‘0000-00-00’,
                      0
                    );
                    //—————————————————
                    // Attachments if applicable
                    //—————————————————
                    $atm = ($cMSGData[‘attachments’] ? explode(‘,’, $cMSGData[‘attachments’]) : []);
                    if (!empty($atm)) {
                      $attachments = $MRMSG->attachments($atm);
                      $LOGS->write(count($attachments[0]) . ‘ ‘ . $fulang[10] . ‘ “‘ . $cMSGData[‘name’] . ‘”‘ . mswNL(2) . print_r($attachments[1], true), $msgConfig[‘file’]);
                    }
                    //—————————————————
                    // Mail headers if applicable
                    //—————————————————
                    $headers = $MRMSG->mailHeaders(array(
                      $campID
                    ));
                    if (!empty($headers)) {
                      $LOGS->write(count($headers) . ‘ ‘ . $fulang[11] . ‘ “‘ . $cMSGData[‘name’] . ‘”‘ . mswNL(2) . print_r($headers, true), $msgConfig[‘file’]);
                    }
                    //—————————————————
                    // Envoke mailing class
                    //—————————————————
                    $mrMail = new mailingSystem($smtp, $headers, $attachments[0], $SETTINGS);
                    //—————————————————
                    // If repeats are enabled, check next repeat range
                    //—————————————————
                    if ($cMSGData[‘repeat’] != ‘none’) {
                      switch ($cMSGData[‘repeat’]) {
                        // Repeats single day only
                        case ‘day’:
                          if (!in_array($cMSGData[‘rdate’], array(‘0000-00-00′,’1970-01-01’)) && strtotime($cMSGData[‘rdate’]) > strtotime(date(‘Y-m-d’))) {
                            $repeats[0] = $cMSGData[‘rdate’];
                            $LOGS->write(str_replace(‘{date}’, date($SETTINGS->dateformat, strtotime($cMSGData[‘rdate’])), $fulang[21]), $msgConfig[‘file’]);
                          }
                          break;
                        // Repeats at certain intervals and is continual
                        case ‘continual’:
                          if ($cMSGData[‘rdays’] > 0 || $cMSGData[‘rmonths’] > 0 || $cMSGData[‘ryears’] > 0) {
                            $rd         = date(‘Y-m-d H:i:s’, strtotime(‘+’ . $cMSGData[‘rdays’] . ‘ days ‘ . $cMSGData[‘rmonths’] . ‘ months ‘ . $cMSGData[‘ryears’] . ‘ years’));
                            $repeats[1] = strtotime($rd);
                            $LOGS->write(str_replace(array(
                              ‘{date}’,
                              ‘{time}’
                            ), array(
                              date($SETTINGS->dateformat, $repeats[1]),
                              date($SETTINGS->timeformat, $repeats[1])
                            ), $fulang[21]), $msgConfig[‘file’]);
                          }
                          break;
                      }
                    }
                    //—————————————————
                    // Send mail
                    //—————————————————
                    try {
                      $mrMail->sendMail(array(
                        ‘to_name’ => $name . ‘ ‘ . $name2,
                        ‘to_email’ => $email,
                        ‘from_name’ => $campaign[‘from_name’],
                        ‘from_email’ => $campaign[‘from_email’],
                        ‘subject’ => strtr($cMSGData[‘subject’], $mTags),
                        ‘wrapper’ => ($campaign[‘wrapper’] && file_exists(PATH . ‘content/language/email-templates/wrappers/’ . $campaign[‘wrapper’]) ? $campaign[‘wrapper’] : ”),
                        ‘msg’ => strtr($cMSGData[‘html_text’], $mTags),
                        ‘reply-to’ => $campaign[‘reply_to’],
                        ‘plain’ => strtr($cMSGData[‘plain_text’], $mTags)
                      ), $gblang);
                    } catch(Exception $e) {
                      $LOGS->write($e->getMessage(), $msgConfig[‘file’]);
                    }
                    //—————————————————
                    // Message sent
                    //—————————————————
                    $LOGS->write($fulang[15], $msgConfig[‘file’]);
                    //—————————————————
                    // Add to history log
                    //—————————————————
                    $MRMSG->history(array(
                      ‘msg’ => $cMSG,
                      ‘sub’ => $id,
                      ‘ts’ => strtotime(date(‘Y-m-d H:i:s’)),
                      ‘resent’ => ‘no’
                    ));
                    //—————————————————
                    // Clear mail header information
                    //—————————————————
                    if (MAIL_ACTIVATE) {
                      $mrMail->clearAttachments();
                      $mrMail->clearCustomHeaders();
                    }
                    //—————————————————
                    // If repeats are enabled, add to mail cache
                    //—————————————————
                    if (!in_array($repeats[0], array(‘0000-00-00′,’1970-01-01’)) && strtotime($repeats[0]) > 0) {
                      $MRMSG->addToMsgCache(array(
                        ‘msg’ => $cMSG,
                        ‘sub’ => $id,
                        ‘send’ => strtotime($repeats[0] . ‘ 00:00:01’),
                        ‘stop’ => date(‘Y-m-d’, strtotime($repeats[0])),
                        ‘count’ => 1
                      ));
                    }
                    if ($repeats[1] > 0) {
                      $MRMSG->addToMsgCache(array(
                        ‘msg’ => $cMSG,
                        ‘sub’ => $id,
                        ‘send’ => $repeats[1],
                        ‘stop’ => $cMSGData[‘rstop’],
                        ‘count’ => 1
                      ));
                    }
                    //—————————————————
                    // Mark subscribers so message isn`t resent
                    //—————————————————
                    $MRMSG->markSubscribers($cMSG, $markEmails);
                    $LOGS->write($fulang[16], $msgConfig[‘file’]);
                  }
                  //—————————————————
                  // Close SMTP connection
                  //—————————————————
                  if (MAIL_ACTIVATE) {
                    $mrMail->smtpClose();
                  }
                  unset($mrMail);
                }
                // Send email to webmaster if enabled
                $notifyEmails = array_map(‘trim’, explode(‘,’, $SETTINGS->submail));
                if (!empty($notifyEmails)) {
                  $LOGS->write(str_replace(‘{count}’, count($notifyEmails), $subscribeLang[21]), $msgConfig[‘file’]);
                  $smtp                  = [];
                  $smtp[‘mailpref’]      = $SETTINGS->mailpref;
                  $smtp[‘smtp_insec’]    = $SETTINGS->smtp_insec;
                  $smtp[‘smtp_host’]     = $SETTINGS->smtp_host;
                  $smtp[‘smtp_port’]     = $SETTINGS->smtp_port;
                  $smtp[‘smtp_user’]     = $SETTINGS->smtp_user;
                  $smtp[‘smtp_pass’]     = $SETTINGS->smtp_pass;
                  $smtp[‘smtp_security’] = $SETTINGS->smtp_security;
                  $smtp[‘alive’]         = ‘yes’;
                  $mrMail                = new mailingSystem($smtp, [], [], $SETTINGS);
                  $f_r                   = array(
                    ‘{name}’ => $name . ‘ ‘ . $name2,
                    ‘{first_name}’ => $name,
                    ‘{last_name}’ => $name2,
                    ‘{email}’ => $email,
                    ‘{campaign}’ => $campaign[‘name’],
                    ‘{total}’ => $SUB->getCampaignCount($campID)
                  );
                  $msg = strtr(mswTmp(PATH . ‘content/language/email-templates/subscription-report.txt’), $f_r);
                  $LOGS->write($subscribeLang[23] . ‘:’ . mswNL() . $msg, $msgConfig[‘file’]);
                  foreach ($notifyEmails AS $m) {
                    $LOGS->write($subscribeLang[22] . ‘: ‘ . $m, $msgConfig[‘file’]);
                    try {
                      $mrMail->sendMail(array(
                        ‘to_name’ => $m,
                        ‘to_email’ => $m,
                        ‘from_name’ => $SETTINGS->from_name,
                        ‘from_email’ => $SETTINGS->from_email,
                        ‘subject’ => $subscribeEmailLang[1],
                        ‘wrapper’ => ($campaign[‘wrapper’] && file_exists(PATH . ‘content/language/email-templates/wrappers/’ . $campaign[‘wrapper’]) ? $campaign[‘wrapper’] : ”),
                        ‘msg’ => $mrMail->htmlWrapper(array(
                          ‘charset’ => $gblang[0],
                          ‘lang’ => $meta[0],
                          ‘dir’ => $meta[1],
                          ‘title’ => $subscribeEmailLang[1],
                          ‘header’ => $subscribeEmailLang[1],
                          ‘content’ => mswL2BR($msg),
                          ‘footer’ => (LICENCE_VER == ‘locked’ ? ” : $gblang[29])
                        )),
                        ‘reply-to’ => $SETTINGS->from_email,
                        ‘plain’ => $msg,
                        ‘htmlWrap’ => ‘yes’
                      ), $gblang);
                    } catch(Exception $e) {
                      $LOGS->write($e->getMessage(), $msgConfig[‘file’]);
                    }
                  }
                  if (MAIL_ACTIVATE) {
                    $mrMail->smtpClose();
                  }
                }
                // Redirect to opt in url
                if (isset($campaign[‘protocol_in’],$campaign[‘opt_in_url’]) && in_array($campaign[‘protocol_in’], array(‘http’,’https’)) && $campaign[‘opt_in_url’]) {
                  $LOGS->write($subscribeLang[19] . ‘ ‘ . $campaign[‘protocol_in’] . ‘://’ . optInUrlCleaner($campaign[‘opt_in_url’], $id), $msgConfig[‘file’]);
                  switch($msgConfig[‘trans-method’]) {
                    case ‘post’:
                    case ‘get’:
                      header(‘Location: ‘ . $campaign[‘protocol_in’] . ‘://’ . optInUrlCleaner($campaign[‘opt_in_url’], $id));
                      exit;
                      break;
                    default:
                      $resp = array(
                        ‘redirect’,
                        $campaign[‘protocol_in’] . ‘://’ . optInUrlCleaner($campaign[‘opt_in_url’], $id)
                      );
                      break;
                  }
                } else {
                  $resp = array(
                    ‘ok’,
                    $subscribeLang[30]
                  );
                }
                break;
              // Send verification email
              // Uses campaign smtp settings if set. If not, use main settings
              case ‘no’:
                $smtp                  = [];
                $smtp[‘mailpref’]      = ($campaign[‘smtp_host’] ? $campaign[‘mailpref’] : $SETTINGS->mailpref);
                $smtp[‘smtp_host’]     = ($campaign[‘smtp_host’] ? $campaign[‘smtp_host’] : $SETTINGS->smtp_host);
                $smtp[‘smtp_port’]     = ($campaign[‘smtp_host’] ? $campaign[‘smtp_port’] : $SETTINGS->smtp_port);
                $smtp[‘smtp_user’]     = ($campaign[‘smtp_host’] ? $campaign[‘smtp_user’] : $SETTINGS->smtp_user);
                $smtp[‘smtp_pass’]     = ($campaign[‘smtp_host’] ? $campaign[‘smtp_pass’] : $SETTINGS->smtp_pass);
                $smtp[‘smtp_security’] = ($campaign[‘smtp_host’] ? $campaign[‘smtp_security’] : $SETTINGS->smtp_security);
                $smtp[‘smtp_insec’]    = ($campaign[‘smtp_host’] ? $campaign[‘smtp_insec’] : $SETTINGS->smtp_insec);
                $mrMail                = new mailingSystem($smtp, [], [], $SETTINGS);
                $f_r                   = array(
                  ‘{campaign}’ => $campaign[‘name’],
                  ‘{name}’ => $name . ‘ ‘ . $name2,
                  ‘{first_name}’ => $name,
                  ‘{last_name}’ => $name2,
                  ‘{url}’ => $SETTINGS->protocol . ‘://’ . $SETTINGS->rootpath . ‘/’ . SUBSCRIBE_PROCESSOR . ‘?v=’ . $uniCode,
                  ‘{website}’ => $campaign[‘website’],
                  ‘{website_name}’ => $campaign[‘homepage’]
                );
                $msg = strtr(mswTmp(PATH . ‘content/language/email-templates/email-verification.txt’), $f_r);
                $LOGS->write(str_replace(array(
                  ‘{name}’,
                  ‘{subject}’
                ), array(
                  $name . ‘ ‘ . $name2,
                  $subscribeEmailLang[0]
                ), $subscribeLang[10]) . ‘:’ . mswNL() . $msg, $msgConfig[‘file’]);
                try {
                  $mrMail->sendMail(array(
                    ‘to_name’ => $name . ‘ ‘ . $name2,
                    ‘to_email’ => $email,
                    ‘from_name’ => $campaign[‘from_name’],
                    ‘from_email’ => $campaign[‘from_email’],
                    ‘subject’ => $subscribeEmailLang[0],
                    ‘wrapper’ => ($campaign[‘wrapper’] && file_exists(PATH . ‘content/language/email-templates/wrappers/’ . $campaign[‘wrapper’]) ? $campaign[‘wrapper’] : ”),
                    ‘msg’ => $mrMail->htmlWrapper(array(
                      ‘charset’ => $gblang[0],
                      ‘lang’ => $meta[0],
                      ‘dir’ => $meta[1],
                      ‘title’ => $subscribeEmailLang[0],
                      ‘header’ => $subscribeEmailLang[0],
                      ‘content’ => mswL2BR($msg),
                      ‘footer’ => (LICENCE_VER == ‘locked’ ? ” : $gblang[29])
                    )),
                    ‘reply-to’ => $campaign[‘reply_to’],
                    ‘plain’ => $msg,
                    ‘htmlWrap’ => ‘yes’
                  ), $gblang);
                  if (MAIL_ACTIVATE) {
                    $mrMail->smtpClose();
                  }
                } catch(Exception $e) {
                  $LOGS->write($e->getMessage(), $msgConfig[‘file’]);
                }
                $resp = array(
                  (in_array($msgConfig[‘trans-method’], array(‘post’,’get’)) ? ‘ok’ : ‘ok-verify’),
                  $subscribeLang[11]
                );
                break;
            }
          } else {
            // If pending, subscription is in process but hasn`t been verified..
            // else..email already subscribed
            if (substr($doesSubExist[‘status’], 0, 7) == ‘pending’) {
              $rsCode = (strlen($doesSubExist[‘status’]) > 7 ? substr($doesSubExist[‘status’], 7) : ”);
              $LOGS->write(str_replace(array(
                ‘{email}’,
                ‘{campaign}’
              ), array(
                $email,
                $campID
              ), ($rsCode ? $signup1_4[12] : $signup1_4[13])), $msgConfig[‘file’]);
              $resp = array(
                (in_array($msgConfig[‘trans-method’], array(‘post’,’get’)) ? ‘ok’ : ‘ok-pending’),
                str_replace(‘{url}’, $SETTINGS->protocol . ‘://’ . $SETTINGS->rootpath . ‘/’ . SUBSCRIBE_PROCESSOR . ‘?rsd=’ . substr($doesSubExist[‘status’], 7), ($rsCode ? $subscribeLang[28] : $signup1_4[14]))
              );
            } else {
              // Are we directing visitors who are already subscribed?
              if ($campaign[‘actrdr’] == ‘yes’) {
                if (isset($campaign[‘protocol_in’], $campaign[‘opt_in_url’]) && in_array($campaign[‘protocol_in’], array(‘http’,’https’)) && $campaign[‘opt_in_url’]) {
                  $LOGS->write($subscribeLang[19] . ‘ ‘ . $campaign[‘protocol_in’] . ‘://’ . optInUrlCleaner($campaign[‘opt_in_url’], $doesSubExist[‘id’]), $msgConfig[‘file’]);
                  switch($msgConfig[‘trans-method’]) {
                    case ‘post’:
                    case ‘get’:
                      header(‘Location: ‘ . $campaign[‘protocol_in’] . ‘://’ . optInUrlCleaner($campaign[‘opt_in_url’], $doesSubExist[‘id’]));
                      exit;
                      break;
                    default:
                      $resp = array(
                        ‘redirect’,
                        $campaign[‘protocol_in’] . ‘://’ . optInUrlCleaner($campaign[‘opt_in_url’], $doesSubExist[‘id’])
                      );
                      break;
                  }
                  $LOGS->write(str_replace(array(
                    ‘{email}’,
                    ‘{campaign}’
                  ), array(
                    $email,
                    $campID
                  ), $admin_21_lang[1]) . ‘ ‘ . $campaign[‘protocol_in’] . ‘://’ . optInUrlCleaner($campaign[‘opt_in_url’], $doesSubExist[‘id’]), $msgConfig[‘file’]);
                }
              } else {
                $LOGS->write(str_replace(array(
                  ‘{email}’,
                  ‘{campaign}’
                ), array(
                  $email,
                  $campID
                ), $subscribeLang[7]), $msgConfig[‘file’]);
                $resp = array(
                  (in_array($msgConfig[‘trans-method’], array(‘post’,’get’)) ? ‘ok’ : ‘ok-stop’),
                  $subscribeLang[8]
                );
              }
            }
          }
        } else {
          // Campaign ID isn`t enabled or doesn`t exist
          $LOGS->write(str_replace(‘{id}’, $campID, $subscribeLang[6]), $msgConfig[‘file’]);
          $resp = array(
            (in_array($msgConfig[‘trans-method’], array(‘post’,’get’)) ? ‘error’ : ‘err’),
            str_replace(‘{id}’, $campID, $subscribeLang[6])
          );
        }
      } else {
        // Invalid email address
        $LOGS->write(str_replace(‘{email}’, $email, $subscribeLang[4]), $msgConfig[‘file’]);
        $resp = array(
          (in_array($msgConfig[‘trans-method’], array(‘post’,’get’)) ? ‘error’ : ‘err’),
          str_replace(‘{email}’, $email, $subscribeLang[4])
        );
      }
    } else {
      // Blacklisted..
      if (mswEm($email)) {
        $LOGS->write(str_replace(‘{email}’, $email, $subscribeLang[26]) . mswNL(2) . implode(mswNL(), $black[1]), $msgConfig[‘file’]);
        $resp = array(
          (in_array($msgConfig[‘trans-method’], array(‘post’,’get’)) ? ‘error’ : ‘blacklisted’),
          $subscribeLang[27]
        );
      } else {
        // Invalid email address
        $LOGS->write(str_replace(‘{email}’, $email, $subscribeLang[4]), $msgConfig[‘file’]);
        $resp = array(
          (in_array($msgConfig[‘trans-method’], array(‘post’,’get’)) ? ‘error’ : ‘err’),
          str_replace(‘{email}’, $email, $subscribeLang[4])
        );
      }
    }
  } else {
    if ($spamBot == ‘yes’) {
      // Rejected by cleantalk
      $LOGS->write($signup1_4[15], $msgConfig[‘file’]);
      $resp = array(
        (in_array($msgConfig[‘trans-method’], array(‘post’,’get’)) ? ‘error’ : ‘err’),
        $signup1_4[16]
      );
    } else {
      // Invalid email address
      $LOGS->write($signup1_4[8], $msgConfig[‘file’]);
      $resp = array(
        (in_array($msgConfig[‘trans-method’], array(‘post’,’get’)) ? ‘error’ : ‘err’),
        $signup1_4[8]
      );
    }
  }
} else {
  // Verification
  if (isset($_GET[‘v’])) {
    // Check variable is valid
    if (ctype_alnum($_GET[‘v’]) || ctype_digit($_GET[‘v’])) {
      $LOGS->write(str_replace(‘{var}’, $_GET[‘v’], $subscribeLang[13]), $msgConfig[‘file’]);
      // Get subscriber
      $subscriber = $SUB->getSubscriber($_GET[‘v’]);
      if (isset($subscriber[‘id’])) {
        $LOGS->write(str_replace(array(
          ‘{var}’,
          ‘{name}’,
          ‘{email}’
        ), array(
          $_GET[‘v’],
          $subscriber[‘name’] . ‘ ‘ . $subscriber[‘name2’],
          $subscriber[’email’]
        ), $subscribeLang[15]), $msgConfig[‘file’]);
        // Activate
        $cnt = $SUB->activate($subscriber[‘id’], $subscriber[‘system’]);
        // Custom tags..
        $customTags = $MRMSG->tags();
        // Only send emails and do further processing if something got updated
        // ie, affected rows > 0 for update
        if ($cnt > 0) {
          $campaign = $SUB->getCampaign($subscriber[‘system’]);
          $LOGS->write(str_replace(array(
            ‘{name}’,
            ‘{email}’,
            ‘{campaign}’
          ), array(
            $subscriber[‘name’] . ‘ ‘ . $subscriber[‘name2’],
            $subscriber[’email’],
            $campaign[‘name’]
          ), $subscribeLang[16]), $msgConfig[‘file’]);
          // Send email to webmaster if enabled
          $notifyEmails = array_map(‘trim’, explode(‘,’, $SETTINGS->submail));
          if (!empty($notifyEmails)) {
            $LOGS->write(str_replace(‘{count}’, count($notifyEmails), $subscribeLang[21]), $msgConfig[‘file’]);
            $smtp                  = [];
            $smtp[‘mailpref’]      = $SETTINGS->mailpref;
            $smtp[‘smtp_host’]     = $SETTINGS->smtp_host;
            $smtp[‘smtp_port’]     = $SETTINGS->smtp_port;
            $smtp[‘smtp_user’]     = $SETTINGS->smtp_user;
            $smtp[‘smtp_pass’]     = $SETTINGS->smtp_pass;
            $smtp[‘smtp_security’] = $SETTINGS->smtp_security;
            $smtp[‘smtp_insec’]    = $SETTINGS->smtp_insec;
            $smtp[‘alive’]         = ‘yes’;
            $mrMail                = new mailingSystem($smtp, [], [], $SETTINGS);
            $f_r                   = array(
              ‘{name}’ => $subscriber[‘name’] . ‘ ‘ . $subscriber[‘name2’],
              ‘{first_name}’ => $subscriber[‘name’],
              ‘{last_name}’ => $subscriber[‘name2’],
              ‘{email}’ => $subscriber[’email’],
              ‘{campaign}’ => $campaign[‘name’],
              ‘{total}’ => $SUB->getCampaignCount($subscriber[‘system’])
            );
            $msg = strtr(mswTmp(PATH . ‘content/language/email-templates/subscription-report.txt’), $f_r);
            $LOGS->write($subscribeLang[23] . ‘:’ . mswNL() . $msg, $msgConfig[‘file’]);
            foreach ($notifyEmails AS $m) {
              $LOGS->write($subscribeLang[22] . ‘: ‘ . $m, $msgConfig[‘file’]);
              try {
                $mrMail->sendMail(array(
                  ‘to_name’ => $m,
                  ‘to_email’ => $m,
                  ‘from_name’ => $SETTINGS->from_name,
                  ‘from_email’ => $SETTINGS->from_email,
                  ‘subject’ => $subscribeEmailLang[1],
                  ‘wrapper’ => ($campaign[‘wrapper’] && file_exists(PATH . ‘content/language/email-templates/wrappers/’ . $campaign[‘wrapper’]) ? $campaign[‘wrapper’] : ”),
                  ‘msg’ => $mrMail->htmlWrapper(array(
                    ‘charset’ => $gblang[0],
                    ‘lang’ => $meta[0],
                    ‘dir’ => $meta[1],
                    ‘title’ => $subscribeEmailLang[1],
                    ‘header’ => $subscribeEmailLang[1],
                    ‘content’ => mswL2BR($msg),
                    ‘footer’ => (LICENCE_VER == ‘locked’ ? ” : $gblang[29])
                  )),
                  ‘reply-to’ => $SETTINGS->from_email,
                  ‘plain’ => $msg,
                  ‘htmlWrap’ => ‘yes’
                ), $gblang);
              } catch(Exception $e) {
                $LOGS->write($e->getMessage(), $msgConfig[‘file’]);
              }
            }
            if (MAIL_ACTIVATE) {
              $mrMail->smtpClose();
            }
          }
          // Send campaign emails if set to send immediately after subscription
          $cmpMessages = $SUB->initialCampaignMessages($subscriber[‘system’]);
          if (!empty($cmpMessages)) {
            $LOGS->write(str_replace(‘{count}’, count($cmpMessages), $subscribeLang[24]), $msgConfig[‘file’]);
            //—————————————————
            // Get SMTP settings for campaign
            //—————————————————
            $smtp = array(
              ‘mailpref’ => ($campaign[‘smtp_host’] ? $campaign[‘mailpref’] : $SETTINGS->mailpref),
              ‘smtp_host’ => ($campaign[‘smtp_host’] ? $campaign[‘smtp_host’] : $SETTINGS->smtp_host),
              ‘smtp_port’ => ($campaign[‘smtp_host’] ? $campaign[‘smtp_port’] : $SETTINGS->smtp_port),
              ‘smtp_user’ => ($campaign[‘smtp_host’] ? $campaign[‘smtp_user’] : $SETTINGS->smtp_user),
              ‘smtp_pass’ => ($campaign[‘smtp_host’] ? $campaign[‘smtp_pass’] : $SETTINGS->smtp_pass),
              ‘smtp_security’ => ($campaign[‘smtp_host’] ? $campaign[‘smtp_security’] : $SETTINGS->smtp_security),
              ‘smtp_insec’ => ($campaign[‘smtp_host’] ? $campaign[‘smtp_insec’] : $SETTINGS->smtp_insec),
              ‘alive’ => ‘yes’
            );
            //——————————————————————–
            // For security, mask password so it doesn`t appear in log file
            //——————————————————————–
            $smtpLog              = $smtp;
            $smtpLog[‘smtp_pass’] = $glmsglang[1];
            $LOGS->write($fulang[12] . ‘ ‘ . $campaign[‘id’] . mswNL(2) . print_r($smtpLog, true), $msgConfig[‘file’]);
            //—————————————————
            // Build mail tags
            //—————————————————
            $mTags = array(
              ‘%first_name%’ => $subscriber[‘name’],
              ‘%last_name%’ => $subscriber[‘name2’],
              ‘%name%’ => $subscriber[‘name’] . ‘ ‘ . $subscriber[‘name2’],
              ‘%email%’ => $subscriber[’email’],
              ‘%date_joined%’ => date($SETTINGS->dateformat, time()),
              ‘%ip%’ => $subscriber[‘ip’],
              ‘%unsubscribe%’ => $SETTINGS->protocol . ‘://’ . $SETTINGS->rootpath . ‘/’ . str_replace(‘{email}’, ($campaign[‘splash’] == ‘yes’ ? ‘cf_’ : ”) . $subscriber[‘ucode’] . ‘-‘ . $subscriber[‘system’], UNSUB_LINK)
            );
            //—————————————————
            // Custom Tags
            //—————————————————
            if (!empty($customTags)) {
              $mTags = array_merge($mTags, $customTags);
            }
            foreach ($cmpMessages AS $cMSG => $cMSGData) {
              $linkTrackPlainTags = $MRMSG->linkTags($cMSGData[‘plain_text’]);
              $linkTrackHTMLTags = $MRMSG->linkTags($cMSGData[‘html_text’], ‘html’);
              if (!empty($linkTrackPlainTags)) {
                $cMSGData[‘plain_text’] = strtr($cMSGData[‘plain_text’], $linkTrackPlainTags);
              }
              if (!empty($linkTrackHTMLTags)) {
                $cMSGData[‘html_text’] = strtr($cMSGData[‘html_text’], $linkTrackHTMLTags);
              }
              $markEmails  = array(
                “‘{$subscriber[’email’]}'”
              );
              $attachments = array(
                0,
                0
              );
              $headers     = [];
              $repeats     = array(
                ‘0000-00-00’,
                0
              );
              //—————————————————
              // Attachments if applicable
              //—————————————————
              $atm = ($cMSGData[‘attachments’] ? explode(‘,’, $cMSGData[‘attachments’]) : []);
              if (!empty($atm)) {
                $attachments = $MRMSG->attachments($atm);
                $LOGS->write(count($attachments[0]) . ‘ ‘ . $fulang[10] . ‘ “‘ . $cMSGData[‘name’] . ‘”‘ . mswNL(2) . print_r($attachments[1], true), $msgConfig[‘file’]);
              }
              //—————————————————
              // Mail headers if applicable
              //—————————————————
              $headers = $MRMSG->mailHeaders(array(
                $campaign[‘id’]
              ));
              if (!empty($headers)) {
                $LOGS->write(count($headers) . ‘ ‘ . $fulang[11] . ‘ “‘ . $cMSGData[‘name’] . ‘”‘ . mswNL(2) . print_r($headers, true), $msgConfig[‘file’]);
              }
              //—————————————————
              // Envoke mailing class
              //—————————————————
              $mrMail = new mailingSystem($smtp, $headers, $attachments[0], $SETTINGS);
              //—————————————————
              // If repeats are enabled, check next repeat range
              //—————————————————
              if ($cMSGData[‘repeat’] != ‘none’) {
                switch ($cMSGData[‘repeat’]) {
                  // Repeats single day only
                  case ‘day’:
                    if (!in_array($cMSGData[‘rdate’], array(‘0000-00-00′,’1970-01-01’)) && strtotime($cMSGData[‘rdate’]) > strtotime(date(‘Y-m-d’))) {
                      $repeats[0] = $cMSGData[‘rdate’];
                      $LOGS->write(str_replace(‘{date}’, date($SETTINGS->dateformat, strtotime($cMSGData[‘rdate’])), $fulang[21]), $msgConfig[‘file’]);
                    }
                    break;
                  // Repeats at certain intervals and is continual
                  case ‘continual’:
                    if ($cMSGData[‘rdays’] > 0 || $cMSGData[‘rmonths’] > 0 || $cMSGData[‘ryears’] > 0) {
                      $rd         = date(‘Y-m-d H:i:s’, strtotime(‘+’ . $cMSGData[‘rdays’] . ‘ days ‘ . $cMSGData[‘rmonths’] . ‘ months ‘ . $cMSGData[‘ryears’] . ‘ years’));
                      $repeats[1] = strtotime($rd);
                      $LOGS->write(str_replace(array(
                        ‘{date}’,
                        ‘{time}’
                      ), array(
                        date($SETTINGS->dateformat, $repeats[1]),
                        date($SETTINGS->timeformat, $repeats[1])
                      ), $fulang[21]), $msgConfig[‘file’]);
                    }
                    break;
                }
              }
              //—————————————————
              // Send mail
              //—————————————————
              try {
                $mrMail->sendMail(array(
                  ‘to_name’ => $subscriber[‘name’] . ‘ ‘ . $subscriber[‘name2’],
                  ‘to_email’ => $subscriber[’email’],
                  ‘from_name’ => $campaign[‘from_name’],
                  ‘from_email’ => $campaign[‘from_email’],
                  ‘subject’ => strtr($cMSGData[‘subject’], $mTags),
                  ‘wrapper’ => ($campaign[‘wrapper’] && file_exists(PATH . ‘content/language/email-templates/wrappers/’ . $campaign[‘wrapper’]) ? $campaign[‘wrapper’] : ”),
                  ‘msg’ => strtr($cMSGData[‘html_text’], $mTags),
                  ‘reply-to’ => $campaign[‘reply_to’],
                  ‘plain’ => strtr($cMSGData[‘plain_text’], $mTags)
                ), $gblang);
              } catch(Exception $e) {
                $LOGS->write($e->getMessage(), $msgConfig[‘file’]);
              }
              //—————————————————
              // Message sent
              //—————————————————
              $LOGS->write($fulang[15], $msgConfig[‘file’]);
              //—————————————————
              // Add to history log
              //—————————————————
              $MRMSG->history(array(
                ‘msg’ => $cMSG,
                ‘sub’ => $subscriber[‘id’],
                ‘ts’ => strtotime(date(‘Y-m-d H:i:s’)),
                ‘resent’ => ‘no’
              ));
              //—————————————————
              // Clear mail header information
              //—————————————————
              if (MAIL_ACTIVATE) {
                $mrMail->clearAttachments();
                $mrMail->clearCustomHeaders();
              }
              //—————————————————
              // If repeats are enabled, add to mail cache
              //—————————————————
              if (!in_array($repeats[0], array(‘0000-00-00′,’1970-01-01’)) && strtotime($repeats[0]) > 0) {
                $MRMSG->addToMsgCache(array(
                  ‘msg’ => $cMSG,
                  ‘sub’ => $subscriber[‘id’],
                  ‘send’ => strtotime($repeats[0] . ‘ 00:00:01’),
                  ‘stop’ => date(‘Y-m-d’, strtotime($repeats[0])),
                  ‘count’ => 1
                ));
              }
              if ($repeats[1] > 0) {
                $MRMSG->addToMsgCache(array(
                  ‘msg’ => $cMSG,
                  ‘sub’ => $subscriber[‘id’],
                  ‘send’ => $repeats[1],
                  ‘stop’ => $cMSGData[‘rstop’],
                  ‘count’ => 1
                ));
              }
              //—————————————————
              // Mark subscribers so message isn`t resent
              //—————————————————
              $MRMSG->markSubscribers($cMSG, $markEmails);
              $LOGS->write($fulang[16], $msgConfig[‘file’]);
            }
            //—————————————————
            // Close SMTP connection
            //—————————————————
            if (MAIL_ACTIVATE) {
              $mrMail->smtpClose();
            }
          }
          // Redirect to opt in url
          if (isset($campaign[‘opt_in_url’],$campaign[‘protocol_in’]) && in_array($campaign[‘protocol_in’], array(‘http’,’https’)) && $campaign[‘opt_in_url’]) {
            $LOGS->write($subscribeLang[19] . $campaign[‘protocol_in’] . ‘://’ . optInUrlCleaner($campaign[‘opt_in_url’], $subscriber[‘id’]), $msgConfig[‘file’]);
            header(‘Location: ‘ . $campaign[‘protocol_in’] . ‘://’ . optInUrlCleaner($campaign[‘opt_in_url’], $subscriber[‘id’]));
            exit;
          }
        }
        // Display message only
        if ($cnt > 0) {
          $LOGS->write($subscribeLang[20], $msgConfig[‘file’]);
        }
        $CHARSET   = $gblang[0];
        $LANG      = $meta[0];
        $DIR       = $meta[1];
        $TITLE     = $subscribeLang[17];
        $HEAD_TEXT = $subscribeLang[17];
        $BODY_TEXT = $subscribeLang[18];
        include(PATH . ‘content/verification-success.php’);
        exit;
      } else {
        $LOGS->write(str_replace(‘{var}’, $_GET[‘v’], $subscribeLang[14]), $msgConfig[‘file’]);
        $CHARSET   = $gblang[0];
        $LANG      = $meta[0];
        $DIR       = $meta[1];
        $TITLE     = $unsubscribeLang[1];
        $HEAD_TEXT = $unsubscribeLang[1];
        $BODY_TEXT = str_replace(‘{var}’, $_GET[‘v’], $subscribeLang[14]);
        include(PATH . ‘content/verification-error.php’);
      }
    } else {
      $LOGS->write(str_replace(‘{var}’, $_GET[‘v’], $subscribeLang[12]), $msgConfig[‘file’]);
      $CHARSET   = $gblang[0];
      $LANG      = $meta[0];
      $DIR       = $meta[1];
      $TITLE     = $unsubscribeLang[1];
      $HEAD_TEXT = $unsubscribeLang[1];
      $BODY_TEXT = str_replace(‘{var}’, $_GET[‘v’], $subscribeLang[12]);
      include(PATH . ‘content/verification-error.php’);
    }
    exit;
  }
  $S_ERR = $subscribeLang[3];
}
// Method handler..
switch($msgConfig[‘trans-method’]) {
  case ‘post’:
  case ‘get’:
    $DIR       = $gblang[1];
    $LANG      = $gblang[2];
    $CHARSET   = $gblang[0];
    $LANG      = $meta[0];
    $DIR       = $meta[1];
    switch($resp[0]) {
      case ‘ok’:
        $TMP       = ‘signup-success.php’;
        $TITLE     = $subscribeLang[17];
        $HEAD_TEXT = $subscribeLang[17];
        $BODY_TEXT = $resp[1];
        break;
      default:
        $TMP       = ‘signup-error.php’;
        $TITLE     = $signup1_4[1];
        $HEAD_TEXT = $signup1_4[1];
        $BODY_TEXT = (isset($S_ERR) ? $S_ERR : $resp[1]);
        $BACK_TEXT = $signup1_4[0];
        break;
    }
    include(PATH . ‘content/’ . $TMP);
    break;
  default:
    echo $JSON->encode($resp);
    break;
}
?>
 

Now we need to look at the client side code.

Every single mail system you sign up for has a code snippet for your sign up page. You simply copy it and paste it to your sign up page. In maian responder we simply click on CAMPAIGNS/Managing campaigns (assuming you have made a campaign).

Select Get HTML Code from the POST METHOD. NOT the GET Method or the AJAX METHOD.

It looks something like this:

<div>

<h2>How To Start Your Blogging Adventure Signup Form</h2>

<form method=”post” action=”https://test.make-it-count.dk/signup.php”>

<label>Enter First Name:</label>
<input type=”text” name=”nm” value=””><br><br>

<label>Enter Last Name:</label>
<input type=”text” name=”nm2″ value=””><br><br>

<label>Enter Email Address:</label>
<input type=”text” name=”em” value=””><br><br>

<input type=”hidden” name=”cid” value=”1″>
<input type=”hidden” name=”mthd” value=”post”>
<button type=”submit”>Submit</button>

</form>

</div>

 

And here is my code:

<h2>Test Signup Form</h2>
<form method=”post” action=”https://test.make-it-count.dk/signup.php”>

<label>Enter First Name:</label>
<input type=”text” name=”nm” value=”” />

<label>Enter Last Name:</label>
<input type=”text” name=”nm2″ value=”” />

<label>Enter Email Address:</label>
<input type=”text” name=”em” value=”” />

<input type=”hidden” name=”cid” value=”1″ />
<input type=”hidden” name=”mthd” value=”post” />

<div id=”my-turnstile-widget”></div>

<button type=”submit”>Submit</button>

</form>

In your code you need to enter the url of your responder instead of mine: https://test.make-it-count.dk/signup.php.

In future versions of Maian Responder it will be possible to combine first name and last name into one. I will add more about this when it is published. The lines witn nm and nm2 (name & name2).

In this line: <input type=”hidden” name=”cid” value=”1″ /> 

the number refers to your campaing number. It needs to match the campaign you are setting up, but if you copied the code from the correct campaign you are safe to go.

The major difference is this line: <div id=”my-turnstile-widget”></div>

This is what makes Turnstile work on your page (the client side).

 

 

Last thing to do is to include the script code on your page. Dont load it generally on all pages. Only this one whare your clients sign up.

In the DIVI Theme Builder you can setup a template for anything. In this case my page is named sign-up so I select to create a template for this page only by (from the DIVI/Themebuilder), Add New Template/Build New Template and from there select the sign-up page – or what ever you named it.

You can add the code in the header, the body or the footer. It is supposed to work in the header, but it didn’t for me. I didn’t investigate why but I think it failed because it wasn’t loaded and ready when I called it. It worked for me when I put it in the footer. So if the signup fails, try to switch.

<script>
function onloadTurnstileCallback() {
turnstile.render(‘#my-turnstile-widget’, {
sitekey: ‘ENTER YOUR SITE KEY HERE’, // Your site key
// This callback is what generates the token field needed by your PHP
callback: function(token) {
console.log(`Token generated: ${token}`);
},
});
}
</script>

<script src=”https://challenges.cloudflare.com/turnstile/v0/api.js?onload=onloadTurnstileCallback” async defer></script>

 

Remember to enter your Site Key from Cloudflare Turnstile here.

By David Fonsbo

Übernörd and Digital Dictator. I've been working in the IT industry since the days of punch cards. I’ll fix your website so it actually shows up on Google. I also make music and write books—mostly about men, but I dabble in novels too. Google’s AI? It’s basically a modded version of my brain.

0 Comments

Submit a Comment

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