-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajax_sendGroupEmail.php
executable file
·117 lines (98 loc) · 3.03 KB
/
ajax_sendGroupEmail.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
<?
include('_common.php');
if (isUserAtLeastAdmin()) {
$input_g = $_POST["group"];
$input_b = $_POST["body"];
$input_c = $_POST["client"];
$input_h = $_POST["html"];
function getGroupRecipients($group)
{
if ($group == '998')
{
return array('[email protected]>');
}
else if ($group == '999')
{
return array('[email protected]');
}
db_connect();
$query = "SELECT * FROM t_user AS u
WHERE u.cancontact=1
AND EXISTS (SELECT * FROM t_user_authority AS ua WHERE ua.user_id = u.id AND ua.authority_id = '".db_escape_string($group)."');";
//$result = mysql_db_query("strstr", $query);
$result = db_runQuery($query);
$arRecipients = array();
if ($result)
{
while ($r = mysql_fetch_array($result))
{
if (mb_strlen($r["email"])>0)
{
$arRecipients[] = $r["email"];
}
}
}
db_freeResult($result);
return $arRecipients;
}
if (mb_strlen(trim($input_g))>0 && (mb_strlen(trim($input_b)))>0)
{
$groupName = ($input_g == '998' || $input_g == '999') ? 'Test group email' : $ar_authorities[$input_g];
$arRecipients = getGroupRecipients($input_g);
//--------
if ($input_c == 'true')
{
$s = 'mailto:'.$addr_bare.'?subject=Group%20email%20to%20'.$groupName.'&body=';
$s .= '@@@' . join(',', $arRecipients); // so client can slpit and count address safely
$r = $s;
}
else
{
$subject = "[$groupName] Support Group Email";
$name = "Support";
$body = $input_b;
if ($input_h == 'true')
{
$prefix = 'This is a MIME encoded multipart message';
$boundary = "MULTIPART_BOUNDARY_".md5(date('r', time()));
$mimetype = "Content-Type: multipart/alternative; boundary=\"".$boundary."\"";
$textpart = "This email is HTML formatted but your emial program is only showing plain text.\r\n";
$body =
"$prefix
--$boundary
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
$textpart
--$boundary
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 8bit
$body
--$boundary--";
}
else
{
$mimetype = "Content-type: text/plain; charset=UTF-8 \n";
}
$headers = "MIME-Version: 1.0 \n"
.$mimetype." \n"
."From: $addr \n"
."Reply-To: $addr \n"
.'X-Mailer: PHP/' . phpversion() . " \n";
$r = True;
foreach ($arRecipients as $to)
{
//echo "$input_c\n$to\n$subject\n$body\n$headers";
$r &= mail($to, $subject, $body, $headers);
//$r &= mb_send_mail("$to", "$subject", "$body", "$headers");
}
}
echo $r;
}
}
/*
Notes:
"Subject: =?UTF-8?B?".base64_encode($subject)."?="
"Subject: =?UTF-8?Q?".imap_8bit($subject)."?=" // better for some clients and use htmlentities
mb_encode_mimeheader()
*/
?>