-
Notifications
You must be signed in to change notification settings - Fork 0
/
mail.php
88 lines (75 loc) · 2.01 KB
/
mail.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
<?php
include_once('PHPMailer-master/PHPMailerAutoload.php');
function connect_db() {
$db_host = 'localhost';
$db_user = 'pm_user';
$db_password = '123321';
$db_name = 'mail_db';
$db_link = mysqli_connect("$db_host", "$db_user", "$db_password", "$db_name");
if(mysqli_connect_errno())
{
echo "Sorry, we were unable to connect to the database.";
exit;
}
return $db_link;
}
function system_send_email($To, $Subject, $Body, $From='notify') {
$email = new PHPMailer();
$email->From = $From."@protonmail.xyz";
$email->FromName = "ProtonMail";
$email->Subject = $Subject;
$email->Body = $Body;
$email->addReplyTo($email->From, $email->FromName);
$email->Sender = $email->From; // Return-Path
$email->addAddress($To);
$email->isHTML(true);
$email->XMailer=' ';
$email->send();
}
function save_email_to_database($email) {
$db_link = connect_db();
$sql = "insert into mail_table values(
default,
'".mysqli_real_escape_string($db_link, $email)."'
)";
$result = mysqli_query($db_link, $sql);
if(!$result) {
return 'Error: '.mysqli_error($db_link);
}
mysqli_close($db_link);
}
function get_message_id_array() {
$db_link = connect_db();
$sql = "select MessageID from mail_table order by MessageID desc";
$result = mysqli_query($db_link, $sql);
if(!$result) {
return 'Error: '.mysqli_error($db_link);
}
$id_array = array();
$n = mysqli_num_rows($result);
if($n > 0) {
while($row = mysqli_fetch_row($result)) {
$id_array[] = $row[0];
}
}
mysqli_free_result($result);
mysqli_close($db_link);
return $id_array;
}
function get_email($id) {
$db_link = connect_db();
$sql = "select Email from mail_table where
MessageID=".mysqli_real_escape_string($db_link, $id);
$result = mysqli_query($db_link, $sql);
if(!$result) {
return 'Error: '.mysqli_error($db_link);
}
$n = mysqli_num_rows($result);
if($n > 0) {
$row = mysqli_fetch_row($result);
}
mysqli_free_result($result);
mysqli_close($db_link);
return $row[0];
}
?>