Email verification with truemail

You can add the feature to check whether a user email is fake or true. Using fluentform_validate_input_item_input_email & truemail API. You will need a true mail API key for this. Here is an example of the code:

add_filter('fluentform_validate_input_item_input_email', function ($default, $field, $formData, $fields, $form) {

    // You may change the following 3 lines
    $targetFormId = 12;
    $errorMessage = 'Looks like email is not correct'; // You may change here
    $trueMailApiKey = 'INSERT_YOUR_TRUEMAIL.IO_API_KEY';

    if ($form->id != $targetFormId) {
        return $default;
    }

    $fieldName = $field['name'];
    if (empty($formData[$fieldName])) {
        return $default;
    }
    $email = $formData[$fieldName];


    $request = wp_remote_get('https://truemail.io/api/v1/verify/single?      address_info=1&timeout=5&access_token='.$trueMailApiKey.'&email='.$email);

    if(is_wp_error($request)) {
        return $default; // request failed so we are skipping validation
    }

    $response = wp_remote_retrieve_body($request);

    $response = json_decode($response, true);

    if($response['result'] == 'valid') {
        return $default;
    }

    return $errorMessage;

}, 10, 5);

For details of the hook fluentform_validate_input_item_input_email check this documentation link.

Powered by BetterDocs

Leave a Reply

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