/include/classes/phpmailer/acheckermailer.class.php

https://github.com/cindyli/AChecker · PHP · 141 lines · 69 code · 21 blank · 51 comment · 11 complexity · 500fdc6410bd8704db6e31f82e568064 MD5 · raw file

  1. <?php
  2. /************************************************************************/
  3. /* AChecker */
  4. /************************************************************************/
  5. /* Copyright (c) 2008 - 2018 */
  6. /* Inclusive Design Institute */
  7. /* */
  8. /* This program is free software. You can redistribute it and/or */
  9. /* modify it under the terms of the GNU General Public License */
  10. /* as published by the Free Software Foundation. */
  11. /************************************************************************/
  12. // $Id$
  13. if (!defined('AC_INCLUDE_PATH')) { exit; }
  14. require(dirname(__FILE__) . '/class.phpmailer.php');
  15. /**
  16. * ACheckerMailer is modified from ATutorMailer
  17. *
  18. * ACheckerMailer extends PHPMailer and sets all the default values
  19. * that are common for AChecker.
  20. * @access public
  21. * @see include/classes/phpmailer/class.phpmailer.php
  22. * @since AChecker 0.2
  23. * @author Cindy Li
  24. */
  25. class ACheckerMailer extends PHPMailer {
  26. /**
  27. * The constructor sets whether to use SMTP or Sendmail depending
  28. * on the value of MAIL_USE_SMTP defined in the config.inc.php file.
  29. * @access public
  30. * @since AChecker 0.2
  31. * @author Joel Kronenberg
  32. */
  33. function __construct() {
  34. if (MAIL_USE_SMTP) {
  35. $this->IsSMTP(); // set mailer to use SMTP
  36. $this->Host = ini_get('SMTP'); // specify main and backup server
  37. } else {
  38. $this->IsSendmail(); // use sendmail
  39. $this->Sendmail = ini_get('sendmail_path');
  40. }
  41. $this->SMTPAuth = false; // turn on SMTP authentication
  42. $this->IsHTML(false);
  43. // send the email in the current encoding:
  44. global $myLang;
  45. $this->CharSet = $myLang->getCharacterSet();
  46. }
  47. /**
  48. * Appends a custom AChecker footer to all outgoing email then sends the email.
  49. * If mail_queue is enabled then instead of sending the mail out right away, it
  50. * places it in the database and waits for the cron to send it using SendQueue().
  51. * The mail queue does not support reply-to, or attachments, and converts all BCCs
  52. * to regular To emails.
  53. * @access public
  54. * @return boolean whether or not the mail was sent (or queued) successfully.
  55. * @see parent::send()
  56. * @since AChecker 0.2
  57. * @author Joel Kronenberg
  58. */
  59. function Send() {
  60. global $_config;
  61. // attach the AChecker footer to the body first:
  62. $this->Body .= "\n\n".'----------------------------------------------'."\n";
  63. $this->Body .= _AC('sent_via_achecker', AC_BASE_HREF);
  64. $this->Body .= "\n"._AC('achecker_home').': http://achecker.ca';
  65. // if this email has been queued then don't send it. instead insert it in the db
  66. // for each bcc or to or cc
  67. if ($_config['enable_mail_queue'] && !$this->attachment)
  68. {
  69. require_once(AC_INCLUDE_PATH.'classes/DAO/MailQueueDAO.class.php');
  70. $mailQueueDAO = new MailQueueDAO();
  71. for ($i = 0; $i < count($this->to); $i++) {
  72. $mailQueueDAO->Create($mailQueueDAO->addSlashes($this->to[$i][0]), $mailQueueDAO->addSlashes($this->to[$i][1]), $mailQueueDAO->addSlashes($this->From), $mailQueueDAO->addSlashes($this->FromName), $mailQueueDAO->addSlashes($this->Subject), $mailQueueDAO->addSlashes($this->Body), $mailQueueDAO->addSlashes($this->CharSet));
  73. }
  74. for($i = 0; $i < count($this->cc); $i++) {
  75. $mailQueueDAO->Create($mailQueueDAO->addSlashes($this->cc[$i][0]), $mailQueueDAO->addSlashes($this->cc[$i][1]), $mailQueueDAO->addSlashes($this->From), $mailQueueDAO->addSlashes($this->FromName), $mailQueueDAO->addSlashes($this->Subject), $mailQueueDAO->addSlashes($this->Body), $mailQueueDAO->addSlashes($this->CharSet));
  76. }
  77. for($i = 0; $i < count($this->bcc); $i++) {
  78. $mailQueueDAO->Create($mailQueueDAO->addSlashes($this->bcc[$i][0]), $mailQueueDAO->addSlashes($this->bcc[$i][1]), $mailQueueDAO->addSlashes($this->From), $mailQueueDAO->addSlashes($this->FromName), $mailQueueDAO->addSlashes($this->Subject), $mailQueueDAO->addSlashes($this->Body), $mailQueueDAO->addSlashes($this->CharSet));
  79. }
  80. return true;
  81. } else {
  82. return parent::Send();
  83. }
  84. }
  85. /**
  86. * Sends all the queued mail. Called by ./admin/cron.php.
  87. * @access public
  88. * @return void
  89. * @since AChecker 0.2
  90. * @author Joel Kronenberg
  91. */
  92. function SendQueue() {
  93. require_once(AC_INCLUDE_PATH.'classes/DAO/MailQueueDAO.class.php');
  94. $mailQueueDAO = new MailQueueDAO();
  95. $rows = $mailQueueDAO->getAll();
  96. $mail_ids = array();
  97. if (is_array($rows))
  98. {
  99. foreach ($rows as $id => $row)
  100. {
  101. $this->ClearAllRecipients();
  102. $this->AddAddress($row['to_email'], $row['to_name']);
  103. $this->From = $row['from_email'];
  104. $this->FromName = $row['from_name'];
  105. $this->CharSet = $row['char_set'];
  106. $this->Subject = $row['subject'];
  107. $this->Body = $row['body'];
  108. parent::Send();
  109. $mail_ids[] = $row['mail_id'];
  110. }
  111. if ($mail_ids)
  112. {
  113. include(AC_INCLUDE_PATH.'classes/DAO/MailQueueDAO.class.php');
  114. $mailQueueDAO = new MailQueueDAO();
  115. $mailQueueDAO->DeleteByIDs($mail_ids);
  116. }
  117. }
  118. }
  119. }
  120. ?>