/
emails_file_upload.php
executable file
·155 lines (127 loc) · 3.87 KB
/
emails_file_upload.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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?
require ("settings.php");
if (isset($_POST["key"])){
$OUTPUT = import_file ($_POST);
}else {
$OUTPUT = get_file();
}
require ("template.php");
function get_file ($err="")
{
$display = "
<h3>Import Email Addresses To Email Marketing Queue</h3>
<table ".TMPL_tblDflts.">
<form action='".SELF."' method='POST' enctype='multipart/form-data'>
<input type='hidden' name='key' value='import'>
$err
<tr>
<th>Enter Name Of Queue</th>
</tr>
<tr class='".bg_class()."'>
<td><input type='text' size='40' name='upload_name'></td>
</tr>
".TBL_BR."
<tr>
<th>Select File To Upload</th>
</tr>
<tr class='".bg_class()."'>
<td><input type='file' name='upload_file'></td>
</tr>
".TBL_BR."
<tr>
<th>Format: 1 email per line</th>
</tr>
<tr>
<th>Eg. </th>
</tr>
<tr class='".bg_class()."'>
<td>test@test.com<br>
test2@test.com<br>
test3@test.com</li></td>
</tr>
".TBL_BR."
<tr>
<td><input type='submit' value='Import'></td>
</tr>
</form>
</table>";
return $display;
}
function import_file ($_POST)
{
$errorlist = "";
$counter = 0;
$newarr = array ();
extract ($_POST);
#check if we have a queue name ...
if (!isset($upload_name) OR strlen($upload_name) < 1)
return get_file ("<li class='err'>Please enter a valid email queue name.</li><br>");
pglib_transaction("BEGIN") or errDie ("Unable to start database transaction.");
#add the group
$sql1 = "INSERT INTO egroups (grouptitle,groupname) VALUES ('".strtolower($upload_name)."','$upload_name')";
$run_sql1 = db_exec($sql1) or errDie ("Unable to record new email group information.");
$file = file($_FILES["upload_file"]["tmp_name"]);
foreach ($file AS $each){
$each = trim($each);
$each = strtolower($each);
$each = str_replace("'","",$each);
$each = str_replace("\"","",$each);
$each = str_replace("\\","",$each);
$each = str_replace("&","",$each);
$each = str_replace("#","",$each);
$each = str_replace("$","",$each);
$each = str_replace("%","",$each);
$each = str_replace("^","",$each);
$each = str_replace("*","",$each);
$each = str_replace("(","",$each);
$each = str_replace(")","",$each);
$each = str_replace("[","",$each);
$each = str_replace("]","",$each);
$each = str_replace("(","",$each);
$each = str_replace("}","",$each);
$each = str_replace("{","",$each);
$each = str_replace(")","",$each);
$each = str_replace(";","",$each);
$each = str_replace(":","",$each);
$each = str_replace("~","",$each);
$each = str_replace("`","",$each);
$each = str_replace("|","",$each);
$each = str_replace("/","",$each);
$each = str_replace("<","",$each);
$each = str_replace(">","",$each);
$each = str_replace("?","",$each);
$each = str_replace("!","",$each);
$each = str_replace("=","",$each);
$each = str_replace("+","",$each);
$each = str_replace(",","",$each);
$newarr[] = $each;
}
$newarr = array_unique ($newarr);
foreach ($newarr AS $key => $line){
$line = trim ($line);
if (strpos($line,"@") != strrpos($line,"@")){
#2 @'s ???
$errorlist .= "<li class='err'>Error on line ".(int)($key+1).": ($line)</li>";
continue;
}
#check if we have a @
if (strpos ($line,"@") === false){
#not found ...
$errorlist .= "<li class='err'>Error on line ".(int)($key+1).": ($line)</li>";
}else {
$sql2 = "INSERT INTO email_groups (email_group,emailaddress,date_added) VALUES ('".strtolower($upload_name)."','$line','now')";
$run_sql2 = db_exec($sql2) or errDie ("Unable to record new email address in email group");
$counter++;
}
}
pglib_transaction ("COMMIT") or errDie ("Unable to commit database transaction.");
return get_file("<li class='err'>$counter Email Addresses Have Been Imported.</li>$errorlist<br>");
// $display = "
// <table ".TMPL_tblDflts.">
// <tr>
// <td>$counter Email Addresses Have Been Imported.</td>
// </tr>
// </table>";
// return $display;
}
?>