-
Notifications
You must be signed in to change notification settings - Fork 0
/
news.class.php
114 lines (98 loc) · 3.04 KB
/
news.class.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
<?php
class News extends Preset implements iNews {
protected
$customers = array();
private
$signature = null,
$server, $user,
$pass, $db;
public function __construct() {
eMM::setMethod("post");
}
protected function assign() {
$mess = null;
$n = $this->debug == "on" ? "\n<br>" : "\n";
foreach ($this->inputFields() as $field) {
$mask = function($label = null) use ($mess, $n, $field) {
return $n.($label ? $label : ucfirst($field)).": ".$this->fields[$field];
};
if (!is_null(($this->fields[$field]))) {
switch ($field) {
case "subject": break;
case "content": $mess .= $n.$n.$this->send->content.$n.$this->signature; break;
default: $this->msg(0, __METHOD__.": Unknown input field: {$field}".$n); break;
}
}
}
return $mess;
}
public function eMailDB($servername, $username, $password, $database) {
$this->server = $servername;
$this->user = $username;
$this->pass = $password;
$this->db = $database;
if (!is_null($servername || $username || $password || $database)) {
$this->status["mysql"] = 1;
if ($this->status["mysql"] == 1) {
try {
$con = new PDO("mysql:host={$this->server}; dbname={$this->db}", $this->user, $this->pass);
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = $con->prepare("SELECT * from emails");
$sql->execute();
$sql->setFetchMode(PDO::FETCH_OBJ);
foreach ($sql as $data) {
$this->customers[$data->user] = $data->email;
}
if ($this->debug == "on") {
$this->msg(3, "Registered Users:");
foreach ($this->customers as $user => $email) {
echo " ".$user;
echo " ".$email."<br>";
}
}
} catch (PDOException $e) {
echo "SQL Error: ".$e->getMessage();
}
} else {
$this->msg(0, __METHOD__.": MySQL connection has not been set yet.");
}
} else {
$this->msg(0, __METHOD__.": All parameters needed.");
}
}
public function signature($sig) {
$this->signature = $sig;
}
protected function setMail() {
if ($this->debug == "on") {
$rep = str_repeat(" ",4);
$this->msg(3, "eMail Test Output:");
foreach ($this->customers as $user => $email) {
echo "<br>".$rep."Recipient : ".$email."<br>"
.$rep."Mail Header : ".$this->m_header."<br>"
.$rep."Subject : <strong>".$this->fields["subject"]."</strong><br>"
.$rep."Content : <br>Hello dear ".$user.", ".$this->message."<br>";
}
} else {
$send = function() {
foreach ($this->customers as $user => $email) {
mail(
$email,
$this->fields["subject"],
"Hello dear ".$user.", ".$this->message,
$this->m_header
);
}
return true;
};
if ($send() == true) {
$this->status["sent"] = 1;
echo "Thank you!<br> Your enquiry has been sent.<br>";
} else {
$this->status["fail"] = 1;
echo "All fields are required to be sent.<br>";
}
}
}
}
?>