-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathemail-varification-with-truemail.php
85 lines (56 loc) · 2.07 KB
/
email-varification-with-truemail.php
1
2
3
4
5
6
7
8
9
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/*
* This snippet will for your email fields where You can verify the provided email
* using truemail api
*/
/*
* Snippet: 1
* This will apply for all the forms in your site
*/
add_filter('fluentform_validate_input_item_input_email', function ($default, $field, $formData, $fields, $form) {
$errorMessage = 'Looks like email is not correct'; // You may change here
$trueMailApiKey = 'INSERT_YOUR_TRUEMAIL.IO_API_KEY';
$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);
/*
* Snippet: 2
* This will apply for only form id: 12
*/
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);