· 7 years ago · Oct 22, 2018, 08:26 PM
1<?php
2function fake_email_generate($type = 'random', $length = 'random', $custom_domain = null) {
3 if ($length == 'random') {
4 $length = rand(1, 16);
5 }
6 $domain = [
7 'google' => [
8 'gmail.com',
9 ],
10 'tencent' => [
11 'foxmail.com',
12 'tencent.com',
13 'vip.qq.com',
14 'qq.com',
15 ],
16 'netease' => [
17 '126.com',
18 '163.com',
19 'yeah.net',
20 'vip.163.com',
21 ],
22 'microsoft' => [
23 'hotmail.com',
24 'outlook.com',
25 ],
26 ];
27 if (!is_null($custom_domain)) {
28 if (is_array($custom_domain)) {
29 $suffix = $custom_domain[array_rand($custom_domain)];
30 } else {
31 $suffix = $custom_domain;
32 }
33 return substr(md5(uniqid()), 0, $length) . "@" . $suffix;
34 }
35 if ($type !== 'random') {
36 if (!isset($domain[$type])) {
37 return false;
38
39 } else {
40 $company_domain = $domain[$type];
41 $suffix = $company_domain[array_rand($company_domain)];
42 return substr(md5(uniqid()), 0, $length) . "@" . $suffix;
43 }
44 } else {
45 $list = $domain[array_rand($domain)];
46 $suffix = $list[array_rand($list)];
47 return substr(md5(uniqid()), 0, $length) . "@" . $suffix;
48 }
49
50}