-
Notifications
You must be signed in to change notification settings - Fork 8
/
mails_add.php
66 lines (60 loc) · 2 KB
/
mails_add.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
<?php
// This page is used to add email addresses to the database (group_mail)
// along with associated tags.
require_once("config.php");
session_start();
if (isset($_SESSION["type"])) {
if ($_SESSION["type"] != 'ML') {
exit("Please go back and try again!");
}
} else {
header("Location: $start_page");
exit();
}
if (isset($_POST['add'])) {
$emails = explode("\n",trim($_POST['emails']));
$tag = trim($_POST['tag']);
if (strpos($tag,",") === FALSE && strpos($tag,":") === FALSE) {
$mysqli = new mysqli($host,$db_user,$db_password,$db_name);
if ($mysqli->connect_errno)
die("Connect failed: ".$mysqli->connect_error);
if (!($stmt = $mysqli->prepare("INSERT INTO group_mail(email,tags) VALUES (?,':$tag:')")))
die("Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error);
$i = 0;
$email = $emails[$i];
if (!$stmt->bind_param("s", $email))
die("Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error);
if (!$stmt->execute())
echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
/* Prepared statement: repeated execution, only data transferred from client to server */
for ($i = 1; $i < count($emails); $i++) {
$email = $emails[$i];
if (!$stmt->execute())
echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}
/* explicit close recommended */
$stmt->close();
$mysqli->close();
} else
echo "Invalid tag!";
}
?>
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Mailer</title>
</head>
<body>
<h1>Mailer</h1>
<a href="mail.php">Group mail</a>
Add new eMails
<a href="mail_history.php">Mail history</a>
<a href="logout.php">Log out</a><br/><br/>
<form action="mails_add.php" method="post">
<input name="tag" placeholder="Tag(s) (eg. tag1::tag2)" type="text" /><br/>
<textarea name="emails" placeholder="Line-separated list of eMail addresses" style="height:300px;width:280px"></textarea><br/>
<input name="add" type="submit" value="Add" />
</form>
</body>
</html>