-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendEmail.php
executable file
·186 lines (154 loc) · 6.58 KB
/
sendEmail.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
include "funcLib.php";
$subject = "";
$message = "";
$query = "select email from people where userid='" . $userid . "'";
$result = mysql_query($query) or die("Could not query: " . mysql_error());
if ($row = mysql_fetch_assoc($result)){
// get the email address of the user
$from = $row["email"];
}
$send = $_REQUEST['send'];
if($send == "Send"){
$ar = array();
$to = "";
$from = $_SESSION["fullname"] . '<' . $from . '>';
foreach($_REQUEST['email'] as $email){
if(strcmp($to,"") != 0){
$to = $email . ", " . $to;
}
else{
$to = $email;
}
}
$subject = $_REQUEST['subject'];
// the server I am hosting this on automatically escapes single and
// double quotes. Since this may not be the case on all servers, I
// explictily remove the escaping
$subject = str_replace("\\"", """,
str_replace("\\'", "'",
str_replace("\\\"", "\"", $subject)));
if(strcmp($subject, " (please fill out)") == 0){
$subject = "A message from " . $_SESSION['fullname'];
}
$message = convertString_no_escape($_REQUEST['message']);
// the server I am hosting this on automatically escapes single and
// double quotes. Since this may not be the case on all servers, I
// explictily remove the escaping
$message = str_replace("\\"", """,
str_replace("\\'", "'",
str_replace("\\\"", "\"", $message)));
if(sendEmail($to, $from, $subject, $message, 0) == 0){
print "<html><body><center><h2>An error occured while sending your email <br>" . $to . "</h2><p><a href=\"javascript:window.close();\">Close Window</a></body></html>";
}
else{
print "<html><body><center><h2>Message Sent Successfully to <br>". $to . "</h2><p><a href=\"javascript:window.close();\">Close Window</a></body></html>";
}
return;
}
$action = $_REQUEST["action"];
if($action != ""){
$recipArray = array();
if($action == "adminNewUser"){
array_push($recipArray, $_REQUEST["newUserEmail"]);
}
else if($action == "addedUser"){
$recip = $_REQUEST["recip"];
$query = "select firstname, lastname, suffix, email from people where userid='" . $recip . "' order by lastname, firstname";
$result = mysql_query($query) or die("Could not query: " . mysql_error());
if ($row = mysql_fetch_assoc($result)){
$name = $row["firstname"] . ' ' . $row["lastname"] . ' ' .
$row["suffix"] . " <" . $row["email"] . ">";
array_push($recipArray, $name);
}
$subject = $_REQUEST["subject"];
$message = str_replace("<br>", "\r\n", $_REQUEST["message"]);
}
elseif($action == "emailPerson"){
$recip = $_REQUEST["recip"];
$query = "select firstname, lastname, suffix, email from people where userid='" . $recip . "' order by lastname, firstname";
$result = mysql_query($query) or die("Could not query: " . mysql_error());
if ($row = mysql_fetch_assoc($result)){
$name = $row["firstname"] . ' ' . $row["lastname"] . ' ' .
$row["suffix"] . " <" . $row["email"] . ">";
array_push($recipArray, $name);
}
}
elseif($action == "emailRecipViewers"){
$recip = $_REQUEST["recip"];
$query = "select firstname, lastname, suffix, email from people,viewList where userid=viewer and pid='" . $recip . "' and viewer !='" . $recip . "' order by lastname, firstname";
$result = mysql_query($query) or die("Could not query: " . mysql_error());
while ($row = mysql_fetch_assoc($result)){
$name = $row["firstname"] . ' ' . $row["lastname"] . ' ' . $row["suffix"] . " <" . $row["email"] . ">";
array_push($recipArray, $name);
}
}
}
?>
<html>
<link rel=stylesheet href=style.css type=text/css>
<body>
<center>
<form action="sendEmail.php" method="POST">
<table style="border-collapse: collapse;" id="AutoNumber1" border="1" bordercolor="#111111" cellpadding="2" cellspacing="0" bgcolor=lightYellow>
<tr><td colspan="2" align="center" bgcolor="#6702cc">
<font size=3 color=white><b>Send Email</b></font>
</td></tr>
<tr><td bgcolor=white colspan=2 align=center>
<br><b>
An email will be sent to each person who has a check next to their name
</b>
<br>
</td></tr>
<tr>
<td valign=top align=right>
<font size="3" face="Arial"><strong>To :</font></strong></td>
<td bgcolor="#eeeeee">
<?php
foreach ($recipArray as $recip){
$p = str_replace(">", ">", (str_replace("<", "<", $recip)));
print "<input type=checkbox name=email[] checked value=\"" .
$recip . "\">" . $p . "<br>";
}
?>
</tr><tr>
<td align=right><font size="3" face="Arial"><strong>CC :</font></strong></td>
<td bgcolor="#eeeeee">
<?php
print "<input type=checkbox name=email[] checked value=\"" .
$_SESSION["fullname"] . '<' . $from . '>' . "\">" . $_SESSION["fullname"] . "<" . $from . ">";
?>
</td>
</tr><tr>
<td align=right><font size="3" face="Arial"><strong>From :</font></strong></td>
<td bgcolor="#eeeeee"><input name=from type=text size=80 value="<?php echo $_SESSION["fullname"] . "<" . $from . ">" ?>" disabled></input></td>
</tr>
<tr>
<td align=right><font size="3" face="Arial"><strong>Subject :</strong></font></td>
<td bgcolor="#eeeeee"><strong><input type="text" size="80" maxlength="100" name="subject" value=<?php echo $subject != "" ? "\"". $subject . "\"" : "\" (please fill out)\"" ?> onfocus="javascript:if(this.value==' (please fill out)') this.value=''"></strong></td>
</tr>
<tr>
<td valign=top align=right><font size="3" face="Arial"><strong>Body :</strong></font></td>
<td>
<textarea name="message" rows="10" cols="80" wrap="PHYSICAL"><?php echo $message ?></textarea>
</td></tr>
<tr>
<td colspan=2 bgcolor="#c0c0c0" align=center>
<input type="submit" name=send value=Send style="font-weight:bold"> <input type="submit" value=Cancel style="font-weight:bold" onclick="javascript:window.close()"></td>
</tr>
</table>
</form>
</center>
</body>
</html>