1- <?php
2- namespace MailboxValidatorLaravel \Validation ;
3-
4- class ValidateEmail{
5- public static $ errorMessage = 'This is a disposable email and should not been used to register. ' ;
6- public $ api_key ;
7-
8- function GetValidateDisposable ($ email ,$ api_key ) {
9- if ($ api_key == '' ) {
10- $ api_key = env ('MBV_API_KEY ' );
11- }
12- $ source = 'laravel ' ;
13- try {
14- // Now we need to send the data to MBV API Key and return back the result.
15- $ results = file_get_contents ('https://api.mailboxvalidator.com/v1/email/disposable?key= ' . $ api_key . '&email= ' .$ email . '&source= ' .$ source );
16-
17- if ($ results == false ) {
18- return 'Unknown error encounter. Please try again later. ' ;
19- } else {
20- // Decode the return json results and return the data as an array.
21- $ data = json_decode ($ results ,true );
22-
23- return $ data ;
24- }
25- } catch (Exception $ e ) {
26- // If execption occur, return the exception
27- return $ e ;
28- }
29- }
30-
31-
32- // $value holds the email address from the form.
33- function ValidateDisposable ($ attribute , $ value , $ parameters , $ validator ) {
34- if (!isset ($ api_key )) {
35- $ api_key = env ('MBV_API_KEY ' );
36- }
37- $ source = 'laravel ' ;
38- try {
39- // Now we need to send the data to MBV API Key and return back the result.
40- $ results = file_get_contents ('https://api.mailboxvalidator.com/v1/email/disposable?key= ' . $ api_key . '&email= ' .$ value . '&source= ' .$ source );
41-
42- // Decode the return json results and return the data as an array.
43- $ data = json_decode ($ results ,true );
44-
45- // Called a function to return message for form validation
46- if (trim ($ data ['error_code ' ]) == '' ) {
47- if ( $ data ['is_disposable ' ] == true ) {
48- $ errorMessage = 'The email ' .$ value .' is disposable email and should not been used to register. ' ;
49- return false ;
50- } else {
51- return true ;
52- }
53- } else {
54- return $ data ['error_code ' ] . $ data ['error_message ' ];
55- }
56-
57- } catch (Exception $ e ) {
58- // If execption occur, return the exception
59- return $ e ;
60- }
61- }
62-
63-
64- }
65-
66-
1+ <?php
2+ namespace MailboxValidatorLaravel \Validation ;
3+
4+ class ValidateEmail{
5+ public static $ errorMessage = 'This is a disposable email and should not been used to register. ' ;
6+ public $ api_key ;
7+
8+ function GetValidateDisposable ($ email ,$ api_key ) {
9+ if ($ api_key == '' ) {
10+ $ api_key = env ('MBV_API_KEY ' );
11+ }
12+ $ source = 'laravel ' ;
13+ try {
14+ // Now we need to send the data to MBV API Key and return back the result.
15+ $ results = file_get_contents ('https://api.mailboxvalidator.com/v1/email/disposable?key= ' . $ api_key . '&email= ' .$ email . '&source= ' .$ source );
16+
17+ if ($ results == false ) {
18+ return 'Unknown error encounter. Please try again later. ' ;
19+ } else {
20+ // Decode the return json results and return the data as an array.
21+ $ data = json_decode ($ results ,true );
22+
23+ return $ data ;
24+ }
25+ } catch (Exception $ e ) {
26+ // If execption occur, return the exception
27+ return $ e ;
28+ }
29+ }
30+
31+
32+ // $value holds the email address from the form.
33+ function ValidateDisposable ($ attribute , $ value , $ parameters , $ validator ) {
34+ if (!isset ($ api_key )) {
35+ $ api_key = env ('MBV_API_KEY ' );
36+ }
37+ $ source = 'laravel ' ;
38+ try {
39+ // Now we need to send the data to MBV API Key and return back the result.
40+ $ results = file_get_contents ('https://api.mailboxvalidator.com/v1/email/disposable?key= ' . $ api_key . '&email= ' .$ value . '&source= ' .$ source );
41+
42+ // Decode the return json results and return the data as an array.
43+ $ data = json_decode ($ results ,true );
44+
45+ // Called a function to return message for form validation
46+ if (trim ($ data ['error_code ' ]) == '' ) {
47+ if ( $ data ['is_disposable ' ] == ' True ' ) {
48+ // $errorMessage = 'The email '.$value.' is disposable email and should not been used to register.';
49+ return false ;
50+ } else {
51+ return true ;
52+ }
53+ } else {
54+ return $ data ['error_code ' ] . $ data ['error_message ' ];
55+ }
56+
57+ } catch (Exception $ e ) {
58+ // If execption occur, return the exception
59+ return $ e ;
60+ }
61+ }
62+
63+
64+ }
65+
66+
6767?>
0 commit comments