PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/src/azora.local/includes/sitemailer_.php

https://gitlab.com/nvtdn2006/azora
PHP | 384 lines | 226 code | 88 blank | 70 comment | 4 complexity | 3b10467935968d848a8cfc97dcc77629 MD5 | raw file
  1. <?php
  2. class SiteMailer
  3. {
  4. public $fromMail;
  5. public $toMail;
  6. public $randomHash;
  7. private $headers;
  8. public $subject;
  9. public $msgBody;
  10. public $attachment;
  11. public $wordwrap;
  12. private $ccMails; // FX.1304.002
  13. private $bccMails;// FX.1304.002
  14. function __construct() {
  15. $config = Factory::getConfig();
  16. $cryptographer = Factory::getCryptographer();
  17. $this->randomHash = $cryptographer->MD5(date('r', time()));
  18. $this->fromMail = $config['PRMSConfig']->noreply_mail;
  19. $this->setheaders();
  20. $this->wordwrap = 70;
  21. $this->ccMails = Array();
  22. $this->bccMails = Array();
  23. }
  24. private function setheaders() {
  25. /*$BccList = array('nakarinb@bluecube.com.sg','bobby.tan@bluecube.com.sg');*/
  26. $this->headers = "To: " . $this->toMail . "\r\n";
  27. $this->headers .= "From: " . $this->fromMail . "\r\n";
  28. if (count($this->ccMails) > 0) {
  29. $this->headers .= "Cc: " . $this->GetCcMails() . " \r\n";
  30. }
  31. if (count($this->bccMails) > 0) {
  32. $this->headers .= "Bcc: nakarinb@gmail.com, " . $this->GetBccMails() . " \r\n";
  33. } else {
  34. $this->headers .= "Bcc: nakarinb@gmail.com\r\n";
  35. }
  36. $this->headers .= "MIME-Version: 1.0\r\n";
  37. //$this->headers .= "Content-Type: multipart/mixed; boundary=\"PHP-mixed-" . $this->randomHash . "\"\r\n";
  38. $this->headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
  39. }
  40. /*+Start FX.1304.002 Add Function */
  41. public function AddCc($mail) {
  42. $this->ccMails[] = $mail;
  43. }
  44. public function AddBcc($mail) {
  45. $this->bccMails[] = $mail;
  46. }
  47. private function GetMailsFromList($mails) {
  48. $line = "";
  49. foreach ($mails as $mail) {
  50. $line .= $mail. ", ";
  51. }
  52. return $line;
  53. }
  54. private function GetCcMails() {
  55. return $this->GetMailsFromList($this->ccMails);
  56. }
  57. private function GetBccMails() {
  58. return $this->GetMailsFromList($this->bccMails);
  59. }
  60. /*-End FX.1304.002 */
  61. public function Send() {
  62. $return = false;
  63. try {
  64. /*if ($this->attachment != '')
  65. {
  66. $this->msgBody .= "\r\n--PHP-mixed-" . $this->randomHash . "--";
  67. $this->msgBody .= $this->attachment;
  68. $this->msgBody .= "\r\n--PHP-mixed-" . $this->randomHash . "--";
  69. }*/
  70. mail($this->toMail, $this->subject, $this->msgBody , $this->headers);
  71. $return = true;
  72. } catch (Exceptin $e) {
  73. throw new Exception($e->getMessage());
  74. }
  75. return $return;
  76. }
  77. private function getContent($filepath) {
  78. $content = '';
  79. ob_start();
  80. include($filepath);
  81. $content = ob_get_contents();
  82. ob_end_clean();
  83. return $content;
  84. }
  85. public function PrepareMail($mailId, $property = array()) {
  86. switch ($mailId)
  87. {
  88. case 'sendActivationToCustomer':
  89. $this->sendActivationToCustomer($property);
  90. break;
  91. case 'sendActivatedToCustomer':
  92. $this->sendActivatedToCustomer($property);
  93. break;
  94. case 'sendPasswordResetToCustomer':
  95. $this->sendPasswordResetToCustomer($property);
  96. break;
  97. case 'sendPointshavebeenstartedaccumulating':
  98. $this->sendPointshavebeenstartedaccumulating($property);
  99. break;
  100. case 'sendPasswordResetToUser':
  101. $this->sendPasswordResetToUser($property);
  102. break;
  103. case 'sendPointshavebeenexpired':
  104. $this->sendPointshavebeenexpired($property);
  105. break;
  106. case 'sendReminderforpointexpiration':
  107. $this->sendReminderforpointexpiration($property);
  108. break;
  109. case 'sendReminderforredemptionToUser':
  110. $this->sendReminderforredemptionToUser($property);
  111. break;
  112. case 'sendRedemptionSubmittedNotify':
  113. $this->sendRedemptionSubmittedNotify($property);
  114. break;
  115. case 'sendRedemptionExpiredToCustomer':
  116. $this->sendRedemptionExpiredToCustomer($property);
  117. break;
  118. case 'sendReminderforbillingToUser':
  119. $this->sendReminderforbillingToUser($property);
  120. break;
  121. case 'sendReminderforcancelledredemptionToUser':
  122. $this->sendReminderforcancelledredemptionToUser($property);
  123. break;
  124. default:
  125. }
  126. }
  127. private function sendActivationToCustomer($property) {
  128. /*$htmlCT = "--PHP-alt-" . $this->randomHash . "\r\n";
  129. $htmlCT .= 'Content-Type: text/html; charset="iso-8859-1"' . "\r\n";
  130. $htmlCT .= 'Content-Transfer-Encoding: 7bit' . "\r\n";*/
  131. $this->msgBody = $this->getContent(WEB_ROOT . DS . 'includes' . DS . 'mail.templates' . DS . 'ActivationToCustomer.html');
  132. preg_match_all('/\{\%[_\w]+\%\}/', $this->msgBody, $placeholders);
  133. foreach ($placeholders[0] as $placeholder) {
  134. $ph = substr($placeholder, 2, strlen($placeholder)-4);
  135. $this->msgBody = preg_replace('/\{\%'.$ph.'\%\}/', $property[$ph], $this->msgBody);
  136. }
  137. /*$this->msgBody = $htmlCT . $this->msgBody;
  138. $this->msgBody .= "\r\n--PHP-alt-" . $this->randomHash . "--";*/
  139. $this->msgBody = wordwrap($this->msgBody, $this->wordwrap);
  140. }
  141. private function sendActivatedToCustomer($property) {
  142. /*$htmlCT = "--PHP-alt-" . $this->randomHash . "\r\n";
  143. $htmlCT .= 'Content-Type: text/html; charset="iso-8859-1"' . "\r\n";
  144. $htmlCT .= 'Content-Transfer-Encoding: 7bit' . "\r\n";*/
  145. $this->msgBody = $this->getContent(WEB_ROOT . DS . 'includes' . DS . 'mail.templates' . DS . 'ActivatedToCustomer.html');
  146. preg_match_all('/\{\%[_\w]+\%\}/', $this->msgBody, $placeholders);
  147. foreach ($placeholders[0] as $placeholder) {
  148. $ph = substr($placeholder, 2, strlen($placeholder)-4);
  149. $this->msgBody = preg_replace('/\{\%'.$ph.'\%\}/', $property[$ph], $this->msgBody);
  150. }
  151. /*$this->msgBody = $htmlCT . $this->msgBody;
  152. $this->msgBody .= "--PHP-alt-" . $this->randomHash . "\r\n";*/
  153. $this->msgBody = wordwrap($this->msgBody, $this->wordwrap);
  154. }
  155. private function sendPasswordResetToCustomer($property) {
  156. /*$htmlCT = "--PHP-alt-" . $this->randomHash . "\r\n";
  157. $htmlCT .= 'Content-Type: text/html; charset="iso-8859-1"' . "\r\n";
  158. $htmlCT .= 'Content-Transfer-Encoding: 7bit' . "\r\n";*/
  159. $this->msgBody = $this->getContent(WEB_ROOT . DS . 'includes' . DS . 'mail.templates' . DS . 'PasswordResetToCustomer.html');
  160. preg_match_all('/\{\%[_\w]+\%\}/', $this->msgBody, $placeholders);
  161. foreach ($placeholders[0] as $placeholder) {
  162. $ph = substr($placeholder, 2, strlen($placeholder)-4);
  163. $this->msgBody = preg_replace('/\{\%'.$ph.'\%\}/', $property[$ph], $this->msgBody);
  164. }
  165. /*$this->msgBody = $htmlCT . $this->msgBody;
  166. $this->msgBody .= "--PHP-alt-" . $this->randomHash . "\r\n";*/
  167. $this->msgBody = wordwrap($this->msgBody, $this->wordwrap);
  168. }
  169. private function sendPointshavebeenstartedaccumulating($property) {
  170. /*$htmlCT = "--PHP-alt-" . $this->randomHash . "\r\n";
  171. $htmlCT .= 'Content-Type: text/html; charset="iso-8859-1"' . "\r\n";
  172. $htmlCT .= 'Content-Transfer-Encoding: 7bit' . "\r\n";*/
  173. $this->msgBody = $this->getContent(WEB_ROOT . DS . 'includes' . DS . 'mail.templates' . DS . 'Pointshavebeenstartedaccumulating.html');
  174. preg_match_all('/\{\%[_\w]+\%\}/', $this->msgBody, $placeholders);
  175. foreach ($placeholders[0] as $placeholder) {
  176. $ph = substr($placeholder, 2, strlen($placeholder)-4);
  177. $this->msgBody = preg_replace('/\{\%'.$ph.'\%\}/', $property[$ph], $this->msgBody);
  178. }
  179. /*$this->msgBody = $htmlCT . $this->msgBody;
  180. $this->msgBody .= "--PHP-alt-" . $this->randomHash . "\r\n";*/
  181. $this->msgBody = wordwrap($this->msgBody, $this->wordwrap);
  182. }
  183. private function sendPasswordResetToUser($property) {
  184. /*$htmlCT = "--PHP-alt-" . $this->randomHash . "\r\n";
  185. $htmlCT .= 'Content-Type: text/html; charset="iso-8859-1"' . "\r\n";
  186. $htmlCT .= 'Content-Transfer-Encoding: 7bit' . "\r\n";*/
  187. $this->msgBody = $this->getContent(WEB_ROOT . DS . 'includes' . DS . 'mail.templates' . DS . 'PasswordResetToUser.html');
  188. preg_match_all('/\{\%[_\w]+\%\}/', $this->msgBody, $placeholders);
  189. foreach ($placeholders[0] as $placeholder) {
  190. $ph = substr($placeholder, 2, strlen($placeholder)-4);
  191. $this->msgBody = preg_replace('/\{\%'.$ph.'\%\}/', $property[$ph], $this->msgBody);
  192. }
  193. /*$this->msgBody = $htmlCT . $this->msgBody;
  194. $this->msgBody .= "--PHP-alt-" . $this->randomHash . "\r\n";*/
  195. $this->msgBody = wordwrap($this->msgBody, $this->wordwrap);
  196. }
  197. private function sendPointshavebeenexpired($property) {
  198. /*$htmlCT = "--PHP-alt-" . $this->randomHash . "\r\n";
  199. $htmlCT .= 'Content-Type: text/html; charset="iso-8859-1"' . "\r\n";
  200. $htmlCT .= 'Content-Transfer-Encoding: 7bit' . "\r\n";*/
  201. $this->msgBody = $this->getContent(WEB_ROOT . DS . 'includes' . DS . 'mail.templates' . DS . 'Pointshavebeenexpired.html');
  202. preg_match_all('/\{\%[_\w]+\%\}/', $this->msgBody, $placeholders);
  203. foreach ($placeholders[0] as $placeholder) {
  204. $ph = substr($placeholder, 2, strlen($placeholder)-4);
  205. $this->msgBody = preg_replace('/\{\%'.$ph.'\%\}/', $property[$ph], $this->msgBody);
  206. }
  207. /*$this->msgBody = $htmlCT . $this->msgBody;
  208. $this->msgBody .= "--PHP-alt-" . $this->randomHash . "\r\n";*/
  209. $this->msgBody = wordwrap($this->msgBody, $this->wordwrap);
  210. }
  211. private function sendReminderforpointexpiration($property) {
  212. /*$htmlCT = "--PHP-alt-" . $this->randomHash . "\r\n";
  213. $htmlCT .= 'Content-Type: text/html; charset="iso-8859-1"' . "\r\n";
  214. $htmlCT .= 'Content-Transfer-Encoding: 7bit' . "\r\n";*/
  215. $this->msgBody = $this->getContent(WEB_ROOT . DS . 'includes' . DS . 'mail.templates' . DS . 'Reminderforpointexpiration.html');
  216. preg_match_all('/\{\%[_\w]+\%\}/', $this->msgBody, $placeholders);
  217. foreach ($placeholders[0] as $placeholder) {
  218. $ph = substr($placeholder, 2, strlen($placeholder)-4);
  219. $this->msgBody = preg_replace('/\{\%'.$ph.'\%\}/', $property[$ph], $this->msgBody);
  220. }
  221. /*$this->msgBody = $htmlCT . $this->msgBody;
  222. $this->msgBody .= "--PHP-alt-" . $this->randomHash . "\r\n";*/
  223. $this->msgBody = wordwrap($this->msgBody, $this->wordwrap);
  224. }
  225. private function sendReminderforredemptionToUser($property) {
  226. /*$htmlCT = "--PHP-alt-" . $this->randomHash . "\r\n";
  227. $htmlCT .= 'Content-Type: text/html; charset="iso-8859-1"' . "\r\n";
  228. $htmlCT .= 'Content-Transfer-Encoding: 7bit' . "\r\n";*/
  229. $this->msgBody = $this->getContent(WEB_ROOT . DS . 'includes' . DS . 'mail.templates' . DS . 'ReminderforredemptionToUser.html');
  230. preg_match_all('/\{\%[_\w]+\%\}/', $this->msgBody, $placeholders);
  231. foreach ($placeholders[0] as $placeholder) {
  232. $ph = substr($placeholder, 2, strlen($placeholder)-4);
  233. $this->msgBody = preg_replace('/\{\%'.$ph.'\%\}/', $property[$ph], $this->msgBody);
  234. }
  235. /*$this->msgBody = $htmlCT . $this->msgBody;
  236. $this->msgBody .= "--PHP-alt-" . $this->randomHash . "\r\n";*/
  237. $this->msgBody = wordwrap($this->msgBody, $this->wordwrap);
  238. }
  239. private function sendRedemptionSubmittedNotify($property) {
  240. /*$htmlCT = "--PHP-alt-" . $this->randomHash . "\r\n";
  241. $htmlCT .= 'Content-Type: text/html; charset="iso-8859-1"' . "\r\n";
  242. $htmlCT .= 'Content-Transfer-Encoding: 7bit' . "\r\n";*/
  243. $this->msgBody = $this->getContent(WEB_ROOT . DS . 'includes' . DS . 'mail.templates' . DS . 'RedemptionSubmittedNotify.html');
  244. preg_match_all('/\{\%[_\w]+\%\}/', $this->msgBody, $placeholders);
  245. foreach ($placeholders[0] as $placeholder) {
  246. $ph = substr($placeholder, 2, strlen($placeholder)-4);
  247. $this->msgBody = preg_replace('/\{\%'.$ph.'\%\}/', $property[$ph], $this->msgBody);
  248. }
  249. /*$this->msgBody = $htmlCT . $this->msgBody;
  250. $this->msgBody .= "--PHP-alt-" . $this->randomHash . "\r\n";*/
  251. $this->msgBody = wordwrap($this->msgBody, $this->wordwrap);
  252. }
  253. private function sendRedemptionExpiredToCustomer($property) {
  254. /*$htmlCT = "--PHP-alt-" . $this->randomHash . "\r\n";
  255. $htmlCT .= 'Content-Type: text/html; charset="iso-8859-1"' . "\r\n";
  256. $htmlCT .= 'Content-Transfer-Encoding: 7bit' . "\r\n";*/
  257. $this->msgBody = $this->getContent(WEB_ROOT . DS . 'includes' . DS . 'mail.templates' . DS . 'RedemptionExpiredToCustomer.html');
  258. preg_match_all('/\{\%[_\w]+\%\}/', $this->msgBody, $placeholders);
  259. foreach ($placeholders[0] as $placeholder) {
  260. $ph = substr($placeholder, 2, strlen($placeholder)-4);
  261. $this->msgBody = preg_replace('/\{\%'.$ph.'\%\}/', $property[$ph], $this->msgBody);
  262. }
  263. /*$this->msgBody = $htmlCT . $this->msgBody;
  264. $this->msgBody .= "--PHP-alt-" . $this->randomHash . "\r\n";*/
  265. $this->msgBody = wordwrap($this->msgBody, $this->wordwrap);
  266. }
  267. private function sendReminderforbillingToUser($property) {
  268. /*$htmlCT = "--PHP-alt-" . $this->randomHash . "\r\n";
  269. $htmlCT .= 'Content-Type: text/html; charset="iso-8859-1"' . "\r\n";
  270. $htmlCT .= 'Content-Transfer-Encoding: 7bit' . "\r\n";*/
  271. $this->msgBody = $this->getContent(WEB_ROOT . DS . 'includes' . DS . 'mail.templates' . DS . 'ReminderforbillingToUser.html');
  272. preg_match_all('/\{\%[_\w]+\%\}/', $this->msgBody, $placeholders);
  273. foreach ($placeholders[0] as $placeholder) {
  274. $ph = substr($placeholder, 2, strlen($placeholder)-4);
  275. $this->msgBody = preg_replace('/\{\%'.$ph.'\%\}/', $property[$ph], $this->msgBody);
  276. }
  277. /*$this->msgBody = $htmlCT . $this->msgBody;
  278. $this->msgBody .= "--PHP-alt-" . $this->randomHash . "\r\n";*/
  279. $this->msgBody = wordwrap($this->msgBody, $this->wordwrap);
  280. }
  281. private function sendReminderforcancelledredemptionToUser($property) {
  282. /*$htmlCT = "--PHP-alt-" . $this->randomHash . "\r\n";
  283. $htmlCT .= 'Content-Type: text/html; charset="iso-8859-1"' . "\r\n";
  284. $htmlCT .= 'Content-Transfer-Encoding: 7bit' . "\r\n";*/
  285. $this->msgBody = $this->getContent(WEB_ROOT . DS . 'includes' . DS . 'mail.templates' . DS . 'ReminderforcancelledredemptionToUser.html');
  286. preg_match_all('/\{\%[_\w]+\%\}/', $this->msgBody, $placeholders);
  287. foreach ($placeholders[0] as $placeholder) {
  288. $ph = substr($placeholder, 2, strlen($placeholder)-4);
  289. $this->msgBody = preg_replace('/\{\%'.$ph.'\%\}/', $property[$ph], $this->msgBody);
  290. }
  291. /*$this->msgBody = $htmlCT . $this->msgBody;
  292. $this->msgBody .= "--PHP-alt-" . $this->randomHash . "\r\n";*/
  293. $this->msgBody = wordwrap($this->msgBody, $this->wordwrap);
  294. }
  295. }
  296. ?>