QuickEmailVerification

This guide will show you how to add email validation using the QuickEmailVerification service. In this guide we’ll create a new plugin to contain the code needed for the integration to work.

Step 1 – create a WordPress plugin

Create a new folder named quform-quickemailverification and inside it create a file named quform-quickemailverification.php

Open the file quform-quickemailverification.php using a text editor and add the following code.

1
2
3
4
5
6
7
8
910
11
12
13
14
15
16
1718
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
<?php
 
/*
 * Plugin Name: Quform QuickEmailVerification Integration
 * Description: Validate email addresses using QuickEmailVerification.
 * Version: 1.0.0
 */
 
add_filter('quform_element_valid_1_3', array('Quform_QuickEmailVerification', 'validate'), 10, 3); 
class Quform_QuickEmailVerification
{
    public static function verify($email)
    {
        require_once 'vendor/autoload.php';
 
        $client = new QuickEmailVerification\Client('API_KEY');        $quickemailverification = $client->quickemailverification();
 
        try {
            $response = $quickemailverification->verify($email);
        } catch (Exception $e) {
            // Ignore exceptions (optional)
            $response = null;
        }
 
        return $response;
    }
 
    public static function validate($valid, $value, $element)
    {
        if ($valid) {
            $response = Quform_QuickEmailVerification::verify($value);
 
            if ($response && isset($response->body) && is_array($response->body) && $response->body['result'] == 'invalid') {
                if (Quform::isNonEmptyString($response->body['did_you_mean'])) {
                    $element->addError(sprintf('Invalid email address - did you mean <b>%s</b>?', $response->body['did_you_mean']));
                } else {
                    $element->addError('Invalid email address');
                }
 
                $valid = false;
            }
        }
 
        return $valid;
    }
}
<?php

/*
 * Plugin Name: Quform QuickEmailVerification Integration
 * Description: Validate email addresses using QuickEmailVerification.
 * Version: 1.0.0
 */

add_filter('quform_element_valid_1_3', array('Quform_QuickEmailVerification', 'validate'), 10, 3);

class Quform_QuickEmailVerification
{
    public static function verify($email)
    {
        require_once 'vendor/autoload.php';

        $client = new QuickEmailVerification\Client('API_KEY');
        $quickemailverification = $client->quickemailverification();

        try {
            $response = $quickemailverification->verify($email);
        } catch (Exception $e) {
            // Ignore exceptions (optional)
            $response = null;
        }

        return $response;
    }

    public static function validate($valid, $value, $element)
    {
        if ($valid) {
            $response = Quform_QuickEmailVerification::verify($value);

            if ($response && isset($response->body) && is_array($response->body) && $response->body['result'] == 'invalid') {
                if (Quform::isNonEmptyString($response->body['did_you_mean'])) {
                    $element->addError(sprintf('Invalid email address - did you mean <b>%s</b>?', $response->body['did_you_mean']));
                } else {
                    $element->addError('Invalid email address');
                }

                $valid = false;
            }
        }

        return $valid;
    }
}
  • On line 9, replace 1_3 with the Email element unique ID
  • On line 17, replace the number API_KEY with your QuickEmailVerification API key
  • You can duplicate line 9 and change the unique ID to another form element unique ID to use the email verification on other forms

Step 2 – install the QuickEmailValidation PHP client

Next you need to install the QuickEmailValidation PHP client using Composer. You can do this on your computer or on the web server. Make sure you have Composer installed, then in a terminal navigate to the directory of the plugin you created in Step 1, then run this command:

composer require quickemailverification/quickemailverification

This will install all required files into the vendor folder within the plugin. Upload the quform-quickemailverification folder to the web server at wp-content/plugins then go to the Plugins page within WordPress and activate the plugin Quform QuickEmailVerification Integration and you’re done.

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