forked from howest-wsde/owaes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.email.php
113 lines (83 loc) · 3.8 KB
/
class.email.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
<?php
require_once('phpmailer/class.phpmailer.php');
require ('phpmailer/PHPMailerAutoload.php');
function decryptor($encText) {
$key = pack("H*", "cf372282683d4802ee035e793218e2e4a8a8eb4f6a1d5675b6a6a289c860abde");
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
$cipherText = base64_decode($encText);
$iv = substr($cipherText, 0, $iv_size);
$cipherText = substr($cipherText, $iv_size);
$text = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $cipherText, MCRYPT_MODE_CBC, $iv);
$block = mcrypt_get_block_size("rijndael_256", "cbc");
$pad = ord($text[($len = strlen($text)) - 1]);
$text = substr($text, 0, strlen($text) - $pad);
return $text;
}
class email {
private $strFromMail = "[email protected]";
private $strFromName = "OWAES";
private $strToMail = "[email protected]";
private $strToName = "OWAES";
private $strSubject = "OWAES";
private $strMessage = "";
private $oTemplate = NULL;
public function email($strTo = "", $strSubject = "", $strMessage = "") {
$this->template("[body]");
if ($strTo != "") {
$this->strToMail = $strTo;
$this->strToName = $strTo;
}
if ($strSubject != "") $this->strSubject = $strSubject;
if ($strMessage != "") $this->strMessage = $strMessage;
if (($strTo != "") && ($strMessage != "")) $this->send();
}
public function setTo($strMail, $strName = "") {
$this->strToMail = $strMail;
$this->strToName = ($strName == "") ? $strMail : $strName;
}
public function setBody($strHTML) {
$this->strMessage = $strHTML;
}
public function template($strTemplate = NULL) {
if (!is_null($strTemplate)) $this->oTemplate = template($strTemplate);
return $this->oTemplate;
}
public function setSubject($strSubject) {
$this->strSubject = $strSubject;
}
public function send() {
$oTemplate = $this->template();
$oTemplate->tag("body", $this->strMessage);
$strMessage = $oTemplate->html();
if (settings("mail", "smtp")) {
$oPHPmailer = new PHPMailer();
$oPHPmailer->IsSMTP();
//$oPHPmailer->SMTPDebug = 2; // enables SMTP debug information (for testing)
// $oPHPmailer->Debugoutput = 'html';
$oPHPmailer->Host = settings("mail", "Host"); // "smtp.gmail.com"; // sets GMAIL as the SMTP server
$oPHPmailer->SMTPAuth = settings("mail", "SMTPAuth"); // true; // enable SMTP authentication
$oPHPmailer->SMTPSecure = settings("mail", "SMTPSecure"); // "ssl"; // sets the prefix to the servier
$oPHPmailer->Port = settings("mail", "Port"); // 465; // set the SMTP port for the GMAIL server
$oPHPmailer->Username = settings("mail", "Username"); // GMAIL username
$oPHPmailer->Password = decryptor(settings("mail", "Password")); // GMAIL password
$oPHPmailer->SetFrom($this->strFromMail, $this->strFromName);
$oPHPmailer->AddAddress($this->strToMail, $this->strToName);
$oPHPmailer->Subject = $this->strSubject;
$oPHPmailer->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$oPHPmailer->MsgHTML($strMessage);
if(!$oPHPmailer->Send()) {
//echo "Mailer Error: " . $oPHPmailer->ErrorInfo;
return FALSE;
} else {
//echo "Message sent!";
return TRUE;
}
} else {
$strHeaders = 'MIME-Version: 1.0' . "\r\n";
$strHeaders .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$strHeaders .= 'To: ' . $this->strToName . ' <' . $this->strToMail . '>' . "\r\n";
//$strHeaders .= 'From: ' . $this->strFromName . ' <' . $this->strFromMail . '>' . "\r\n";
mail($this->strToMail, $this->strSubject, $strMessage, $strHeaders);
}
}
}