2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2010 */
6 /* Inclusive Design Institute */
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 /************************************************************************/
13 if (!defined('TR_INCLUDE_PATH')) { exit; }
15 require(dirname(__FILE__) . '/class.phpmailer.php');
18 * TransformableMailer is modified from TransformableMailer
20 * TransformableMailer extends PHPMailer and sets all the default values
21 * that are common for Transformable.
23 * @see include/classes/phpmailer/class.phpmailer.php
24 * @since Transformable 0.1
27 class TransformableMailer extends PHPMailer {
30 * The constructor sets whether to use SMTP or Sendmail depending
31 * on the value of MAIL_USE_SMTP defined in the config.inc.php file.
34 * @author Joel Kronenberg
36 function TransformableMailer() {
38 $this->IsSMTP(); // set mailer to use SMTP
39 $this->Host = ini_get('SMTP'); // specify main and backup server
41 $this->IsSendmail(); // use sendmail
42 $this->Sendmail = ini_get('sendmail_path');
45 $this->SMTPAuth = false; // turn on SMTP authentication
48 // send the email in the current encoding:
50 $this->CharSet = $myLang->getCharacterSet();
54 * Appends a custom AContent footer to all outgoing email then sends the email.
55 * If mail_queue is enabled then instead of sending the mail out right away, it
56 * places it in the database and waits for the cron to send it using SendQueue().
57 * The mail queue does not support reply-to, or attachments, and converts all BCCs
58 * to regular To emails.
60 * @return boolean whether or not the mail was sent (or queued) successfully.
63 * @author Joel Kronenberg
68 // attach the AContent footer to the body first:
69 $this->Body .= "\n\n".'----------------------------------------------'."\n";
70 $this->Body .= _AT(array('sent_via_transformable', TR_BASE_HREF));
72 $this->Body .= "\n"._AT('home').': http://atutor.ca';
74 // if this email has been queued then don't send it. instead insert it in the db
75 // for each bcc or to or cc
76 if ($_config['enable_mail_queue'] && !$this->attachment)
78 require_once(TR_INCLUDE_PATH.'classes/DAO/MailQueueDAO.class.php');
79 $mailQueueDAO = new MailQueueDAO();
81 for ($i = 0; $i < count($this->to); $i++) {
82 $mailQueueDAO->Create(addslashes($this->to[$i][0]), addslashes($this->to[$i][1]), addslashes($this->From), addslashes($this->FromName), addslashes($this->Subject), addslashes($this->Body), addslashes($this->CharSet));
84 for($i = 0; $i < count($this->cc); $i++) {
85 $mailQueueDAO->Create(addslashes($this->cc[$i][0]), addslashes($this->cc[$i][1]), addslashes($this->From), addslashes($this->FromName), addslashes($this->Subject), addslashes($this->Body), addslashes($this->CharSet));
87 for($i = 0; $i < count($this->bcc); $i++) {
88 $mailQueueDAO->Create(addslashes($this->bcc[$i][0]), addslashes($this->bcc[$i][1]), addslashes($this->From), addslashes($this->FromName), addslashes($this->Subject), addslashes($this->Body), addslashes($this->CharSet));
92 return parent::Send();
97 * Sends all the queued mail. Called by ./admin/cron.php.
100 * @since AContent 0.2
101 * @author Joel Kronenberg
103 function SendQueue() {
106 require_once(TR_INCLUDE_PATH.'classes/DAO/MailQueueDAO.class.php');
107 $mailQueueDAO = new MailQueueDAO();
108 $rows = $mailQueueDAO->getAll();
114 foreach ($rows as $id => $row)
116 $this->ClearAllRecipients();
118 $this->AddAddress($row['to_email'], $row['to_name']);
119 $this->From = $row['from_email'];
120 $this->FromName = $row['from_name'];
121 $this->CharSet = $row['char_set'];
122 $this->Subject = $row['subject'];
123 $this->Body = $row['body'];
127 $mail_ids .= $row['mail_id'].',';
131 include(TR_INCLUDE_PATH.'classes/DAO/MailQueueDAO.class.php');
132 $mailQueueDAO = new MailQueueDAO();
134 $mail_ids = substr($mail_ids, 0, -1); // remove the last comma
135 $mailQueueDAO->DeleteByIDs($mail_ids);