-
Notifications
You must be signed in to change notification settings - Fork 2
/
mail.php
148 lines (135 loc) · 3.83 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
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
<?php
require_once(__DIR__ . "/secrets.php");
require_once(__DIR__ . "/global.php");
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require_once(__DIR__ . "/other/PHPMailer/Exception.php");
require_once(__DIR__ . "/other/PHPMailer/PHPMailer.php");
require_once(__DIR__ . "/other/PHPMailer/SMTP.php");
function SetServerSettings($mail, $IsElastic = IS_ELASTIC)
{
//Server settings
if ($IsElastic)
{
$mail->SMTPDebug = 0; // 2=Enable verbose debug output
$mail->isSMTP();
$mail->Host = "smtp.elasticemail.com"; //elastice
$mail->SMTPAuth = true;
$mail->Username = MAIL_ADDR;
$mail->Password = SECRET_MAIL_PASS_ELASTIC;
$mail->Port = 2525; // elastic
}
else
{
$mail->SMTPDebug = 0; // 2=Enable verbose debug output
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = MAIL_ADDR;
$mail->Password = SECRET_MAIL_PASS;
$mail->SMTPSecure = 'ssl'; // google ssl
$mail->Port = 465; // google ssl
}
return $mail;
}
function SendMail($mailAddr, $subject, $body, $altbody)
{
$mail = new PHPMailer(true);
try {
$mail = SetServerSettings($mail);
//Recipients
$mail->setFrom(MAIL_ADDR, 'Test VPN');
$mail->addAddress($mailAddr);
//Content
$mail->isHTML(true);
$mail->Subject = "$subject";
$mail->Body = "$body";
$mail->AltBody = "$altbody";
$mail->send();
return 'Message has been sent';
} catch (Exception $e) {
return 'Message could not be sent. Mailer Error: ' . (string)$mail->ErrorInfo;
}
}
function SendMailPasswd($mailAddr, $token)
{
//Content
$reset_url = "https://" . DOMAIN_NAME . "/new_password.php?token=$token";
$Subject = "Free TestVPN";
$Body = "
Hello TestVPN User!</br>\n
</br>\n
Someone requested a password reset on your mail.</br>\n
If this was not you ignore this mail.</br>\n
</br>\n
If you want to change your password click <a href=\"$reset_url\">here</a>.
";
$AltBody = "
Hello TestVPN User!
Someone requested a password reset on your mail.
If this was not you ignore this mail.
If you want to change your password go to this url:
$reset_url
";
return SendMail($mailAddr, $Subject, $Body, $AltBody);
}
function SendMailConfig($mailAddr, $username)
{
$mail = new PHPMailer(true);
try {
$mail = SetServerSettings($mail, false); // elastic mails with attachement get deleted
//Recipients
$mail->setFrom(MAIL_ADDR, 'Test VPN');
$mail->addAddress($mailAddr);
//Attachments
$certs = 0;
$aConfig = $_SESSION['Config'];
for ($i=0;$i<10;$i++)
{
$cert_name=$username . "-" . $i . ".ovpn";
$cert_path=CERT_PATH . $cert_name;
if (file_exists($cert_path))
{
if ($aConfig[$i] === "")
{
$mail->addAttachment($cert_path, $cert_name);
}
else
{
$mail->addAttachment($cert_path, $aConfig[$i] . '.ovpn');
}
$certs++;
}
}
//Content
$mail->isHTML(true);
$mail->Subject = "Free TestVPN configs";
$mail->Body = "
<html>
<head>
</head>
<body>
Hello <b>User!</b></br>\n
</br>\n
You have $certs config files.</br>\n
Use one for each device you want to connect to the VPN.</br>\n
</br>\n
Download the <a href=\"https://openvpn.net/index.php/open-source/downloads.html\">OpenVPN client</a> for windows</br>\n
On macOS download <a href=\"https://tunnelblick.net/index.html\">Tunnelblick</a>.</br>\n
For android and iOS your can find a OpenVPN app in google play and app store.</br>\n
</br>\n
</br>\n
If you need help there are installation guides on youtube for <a href=\"https://www.youtube.com/watch?v=PrCsNQ_gKwM\">iOS</a>,
<a href=\"https://www.youtube.com/watch?v=9zqbkJQWu28\">macOS</a>,
<a href=\"https://www.youtube.com/watch?v=lr_0ajj4uXQ\">windows</a>
</body>
</html>
";
$mail->AltBody = "Hello! You have $certs!";
$mail->send();
return 'Message has been sent';
} catch (Exception $e) {
return 'Message could not be sent. Mailer Error: ' . (string)$mail->ErrorInfo;
}
}
?>