2 // +----------------------------------------------------------------------+
3 // | Anuko Time Tracker
4 // +----------------------------------------------------------------------+
5 // | Copyright (c) Anuko International Ltd. (https://www.anuko.com)
6 // +----------------------------------------------------------------------+
7 // | LIBERAL FREEWARE LICENSE: This source code document may be used
8 // | by anyone for any purpose, and freely redistributed alone or in
9 // | combination with other software, provided that the license is obeyed.
11 // | There are only two ways to violate the license:
13 // | 1. To redistribute this code in source form, with the copyright
14 // | notice or license removed or altered. (Distributing in compiled
15 // | forms without embedded copyright notices is permitted).
17 // | 2. To redistribute modified versions of this code in *any* form
18 // | that bears insufficient indications that the modifications are
19 // | not the work of the original author(s).
21 // | This license applies to this document only, not any other software
22 // | that it may be combined with.
24 // +----------------------------------------------------------------------+
26 // | https://www.anuko.com/time_tracker/credits.htm
27 // +----------------------------------------------------------------------+
31 var $mCharSet = 'iso-8859-1';
32 var $mContentType = 'text/plain';
37 function __construct($type='mail') {
38 $this->mMailMode = $type;
41 function setMailMode($value) {
42 $this->mMailMode = $value;
45 function setCharSet($value) {
46 $this->mCharSet = $value;
49 function setContentType($value) {
50 $this->mContentType = $value;
53 function setReceiver($value) {
54 $this->mReceiver = $value;
57 function setReceiverCC($value) {
58 $this->mReceiverCC = $value;
61 function setSender($value) {
62 $this->mSender = $value;
65 function send($subject, $data) {
66 $data = chunk_split(base64_encode($data));
67 $subject = Mailer::mimeEncode($subject, $this->mCharSet);
69 $headers = array('From' => $this->mSender, 'To' => $this->mReceiver);
70 if (isset($this->mReceiverCC)) $headers = array_merge($headers, array('CC' => $this->mReceiverCC));
71 $headers = array_merge($headers, array(
72 'Subject' => $subject,
73 'MIME-Version' => '1.0',
74 'Content-Type' => $this->mContentType.'; charset='.$this->mCharSet,
75 'Content-Transfer-Encoding' => 'BASE64'));
78 require_once('Mail.php');
80 $recipients = $this->mReceiver;
81 switch ($this->mMailMode) {
83 $mail = Mail::factory('mail');
87 // Mail_smtp does not do CC -> recipients conversion
88 if (!empty($this->mReceiverCC)) {
89 // make exactly one space after a comma
90 $recipients .= ', ' . preg_replace('/,[[:space:]]+/', ', ', $this->mReceiverCC);
93 $host = defined('MAIL_SMTP_HOST') ? MAIL_SMTP_HOST : 'localhost';
94 $port = defined('MAIL_SMTP_PORT') ? MAIL_SMTP_PORT : '25';
95 $username = defined('MAIL_SMTP_USER') ? MAIL_SMTP_USER : null;
96 $password = defined('MAIL_SMTP_PASSWORD') ? MAIL_SMTP_PASSWORD : null;
97 $auth = (defined('MAIL_SMTP_AUTH') && isTrue(MAIL_SMTP_AUTH)) ? true : false;
98 $debug = (defined('MAIL_SMTP_DEBUG') && isTrue(MAIL_SMTP_DEBUG)) ? true : false;
100 $mail = Mail::factory('smtp', array ('host' => $host,
102 'username' => $username,
103 'password' => $password,
109 if (defined('MAIL_SMTP_DEBUG') && isTrue(MAIL_SMTP_DEBUG))
110 PEAR::setErrorHandling(PEAR_ERROR_PRINT);
112 $res = $mail->send($recipients, $headers, $data);
113 return (!is_a($res, 'PEAR_Error'));
116 function mimeEncode($in_str, $charset) {
118 if ($out_str && $charset) {
119 $start = '=?'.strtoupper($charset).'?B?';
121 $out_str = base64_encode($out_str);
122 $out_str = $start . $out_str . $end;