1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/* zLibrary |
3
|
|
|
* |
4
|
|
|
* This program is free software: you can redistribute it and/or modify |
5
|
|
|
* it under the terms of the GNU Affero General Public License as published by |
6
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
7
|
|
|
* (at your option) any later version. |
8
|
|
|
* |
9
|
|
|
* This program is distributed in the hope that it will be useful, |
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12
|
|
|
* GNU Affero General Public License for more details. |
13
|
|
|
* |
14
|
|
|
* You should have received a copy of the GNU Affero General Public License |
15
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
class Email |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param string $email |
23
|
|
|
* @param string $subject |
24
|
|
|
* @param string $body |
25
|
|
|
* @return string |
26
|
|
|
*/ |
27
|
|
|
public static function send($email, $subject, $body) |
28
|
|
|
{ |
29
|
|
|
if($email == "[email protected]") |
30
|
|
|
return "Mail address is [email protected] - which isn't a real address, please fix it so we can send mails to you!"; |
31
|
|
|
|
32
|
|
|
global $emailsmtp, $emailport, $emailusername, $emailpassword, $sentfromemail, $sentfromdomain, $baseDir; |
33
|
|
|
$mail = new PHPMailer(); |
34
|
|
|
$mail->isSMTP(); |
35
|
|
|
$mail->SMTPDebug = 0; |
36
|
|
|
$mail->SMTPAuth = true; |
37
|
|
|
$mail->Host = $emailsmtp; |
38
|
|
|
$mail->Port = $emailport; |
39
|
|
|
$mail->Username = $emailusername; |
40
|
|
|
$mail->Password = $emailpassword; |
41
|
|
|
$mail->SetFrom($sentfromemail, $sentfromdomain); |
42
|
|
|
$mail->Subject = $subject; |
43
|
|
|
$mail->Body = $body; |
44
|
|
|
$mail->AddAddress($email); |
45
|
|
|
if (!$mail->Send()) { |
46
|
|
|
Log::log("Error sending email to $email: " . $mail->ErrorInfo); |
47
|
|
|
echo "Mail error: " . $mail->ErrorInfo; |
48
|
|
|
} else { |
49
|
|
|
Log::log("Email sent to $email with subject '$subject'"); |
50
|
|
|
return "Success"; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|