-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
email_IsValid()
133 lines (133 loc) · 4.26 KB
/
email_IsValid()
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/**
*
* Validate an email address
*
* @author John B. Abela <github:johnabela>
* @copyright 2019 https://4cm.com/
* @created July 18, 2019
* @version 1.0.0
* @see https://gist.github.com/johnabela/9a41191e9946ed59addae447b3c72206
* @param $email
* @return bool
* @usage if ( !email_IsValid($Email) ) { die('The email address you entered does not appear to be a valid email address.'); }
*/
function email_IsValid($email) {
//
//
///////////////////////////////////////////////////////////////////////
// Kill some email injection methods.
// The following characters are never used in an email address and are
// only used for email injections, which is vital we kill.
///////////////////////////////////////////////////////////////////////
//
$email = str_replace(';','', $email); // Kill: Multiple Email Addresses
$email = str_replace(',','', $email); // Kill: Multiple Email Addresses
$email = str_replace(' ','', $email); // Kill: Spaces don't belong in emails
$email = str_replace(':','', $email); // Kill: Content-Type:multipart/mixed & header:
$email = str_replace('/','', $email); // Kill: Content-Type:multipart/mixed
$email = str_replace('=','', $email); // Kill: boundary=
$email = str_replace('%','', $email); // Kill: Carriage return (such as 0x0D/%0D in hexadecimal)
$email = str_replace('\r','', $email); // Kill: Carriage returns
$email = str_replace('\n','', $email); // Kill: Carriage returns
$email = str_replace('&','', $email); // Kill: @ character translation (such as @)
//
//
///////////////////////////////////////////////////////////////////////
// Correct common tld typos
///////////////////////////////////////////////////////////////////////
//
if ( substr($email, -3) == 'cmo' ) {
//
$email = substr($email, 0, -3) . 'com';
//
}
elseif ( substr($email, -3) == 'moc' ) {
//
$email = substr($email, 0, -3) . 'com';
//
}
elseif ( substr($email, -3) == 'ocm' ) {
//
$email = substr($email, 0, -3) . 'com';
//
}
elseif ( substr($email, -3) == 'nte' ) {
//
$email = substr($email, 0, -3) . 'net';
//
}
elseif ( substr($email, -3) == 'etn' ) {
//
$email = substr($email, 0, -3) . 'net';
//
}
elseif ( substr($email, -3) == 'ogr' ) {
//
$email = substr($email, 0, -3) . 'org';
//
}
elseif ( substr($email, -3) == 'rog' ) {
//
$email = substr($email, 0, -3) . 'org';
//
}
elseif ( substr($email, -3) == 'gor' ) {
//
$email = substr($email, 0, -3) . 'org';
//
}
//
//
///////////////////////////////////////////////////////////////////////
// Does email address have a @ and . symbol?
///////////////////////////////////////////////////////////////////////
//
if ((strpos($email,'@') === false) || (strpos($email,'.') === false)) {
//
return false;
//
}
//
//
///////////////////////////////////////////////////////////////////////
// Does email address have text between @ and .
///////////////////////////////////////////////////////////////////////
//
if (!trim(strstr(strstr($email,'@'),'.',true),'@.')) {
//
return false;
//
}
//
//
///////////////////////////////////////////////////////////////////////
// Does email address have text after period
///////////////////////////////////////////////////////////////////////
//
if ( !explode('.', substr($email, strrpos($email, '@')+1))[1] ) {
//
return false;
//
}
//
//
///////////////////////////////////////////////////////////////////////
// Does email pass dns check?
///////////////////////////////////////////////////////////////////////
//
if (function_exists('idn_to_ascii') && defined('INTL_IDNA_VARIANT_UTS46')) {
//
$domain = idn_to_ascii(ltrim(stristr($email, '@'), '@') . '.', 0, INTL_IDNA_VARIANT_UTS46);
//
if ( !checkdnsrr($domain, 'ANY') ) {
//
return false;
//
}
//
}
//
return true;
//
}