2
/* vim:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab: */
7
* LICENSE: GNU General Public License, version 2 (GPLv2)
8
* Copyright (c) 2001 - 2011 Ampache.org All Rights Reserved
10
* This program is free software; you can redistribute it and/or
11
* modify it under the terms of the GNU General Public License v2
12
* as published by the Free Software Foundation.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software
21
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
* @authro Karl Vollmer <vollmer@ampache.org>
25
* @copyright 2001 - 2011 Ampache.org
26
* @license http://opensource.org/licenses/gpl-2.0 GPLv2
27
* @link http://www.ampache.org/
33
* This class handles the Mail
36
* @copyright 2001 - 2011 Ampache.org
37
* @license http://opensource.org/licenses/gpl-2.0 GPLv2
38
* @link http://www.ampache.org/
42
// The message, recipient and from
46
public $recipient_name;
53
* This does nothing. Much like goggles.
55
public function __construct() {
64
* Does the config magic to figure out the "system" email sender and
65
* sets it as the sender.
67
public function set_default_sender() {
68
$user = Config::get('mail_user');
73
$domain = Config::get('mail_domain');
75
$domain = 'example.com';
78
$fromname = Config::get('mail_name');
80
$fromname = 'Ampache';
83
$this->sender = $user . '@' . $domain;
84
$this->sender_name = $fromname;
85
} // set_default_sender
89
* This returns an array of userids for people who have e-mail
90
* addresses based on the passed filter
92
public static function get_users($filter) {
97
$sql = "SELECT * FROM `user` WHERE `email` IS NOT NULL";
100
$sql = "SELECT * FROM `user` WHERE `access`='25' AND `email` IS NOT NULL";
103
$sql = "SELECT * FROM `user` WHERE `access`='100' AND `email` IS NOT NULL";
106
$inactive = time() - (30*86400);
107
$sql = "SELECT * FROM `user` WHERE `last_seen` <= '$inactive' AND `email` IS NOT NULL";
109
} // end filter switch
111
$db_results = Dba::read($sql);
115
while ($row = Dba::fetch_assoc($db_results)) {
116
$results[] = array('id'=>$row['id'],'fullname'=>$row['fullname'],'email'=>$row['email']);
125
* This should be run if we want to add some statistics to this e-mail,
126
* appends to self::$message
128
public function add_statistics($methods) {
136
* This actually sends the mail, how amazing
138
public function send($phpmailer = null) {
140
$mailtype = Config::get('mail_type');
142
if ($phpmailer == null) {
143
$mail = new PHPMailer();
145
$recipient_name = $this->recipient_name;
146
if(function_exists('mb_encode_mimeheader')) {
147
$recipient_name = mb_encode_mimeheader($recipient_name);
149
$mail->AddAddress($this->recipient, $recipient_name);
155
$mail->CharSet = Config::get('site_charset');
156
$mail->Encoding = 'base64';
157
$mail->From = $this->sender;
158
$mail->Sender = $this->sender;
159
$mail->FromName = $this->sender_name;
160
$mail->Subject = $this->subject;
162
if(function_exists('mb_eregi_replace')) {
163
$this->message = mb_eregi_replace("\r\n", "\n", $this->message);
165
$mail->Body = $this->message;
167
$sendmail = Config::get('sendmail_path');
168
$sendmail = $sendmail ? $sendmail : '/usr/sbin/sendmail';
169
$mailhost = Config::get('mail_host');
170
$mailhost = $mailhost ? $mailhost : 'localhost';
171
$mailport = Config::get('mail_port');
172
$mailport = $mailport ? $mailport : 25;
173
$mailauth = Config::get('mail_auth');
174
$mailuser = Config::get('mail_auth_user');
175
$mailuser = $mailuser ? $mailuser : '';
176
$mailpass = Config::get('mail_auth_pass');
177
$mailpass = $mailpass ? $mailpass : '';
182
$mail->Host = $mailhost;
183
$mail->Port = $mailport;
184
if($mailauth == true) {
185
$mail->SMTPAuth = true;
186
$mail->Username = $mailuser;
187
$mail->Password = $mailpass;
189
if ($mailsecure = Config::get('mail_secure_smtp')) {
190
$mail->SMTPSecure = ($mailsecure == 'ssl') ? 'ssl' : 'tls';
195
$mail->Sendmail = $sendmail;
203
$retval = $mail->send();
204
if( $retval == true ) {
211
public function send_to_group($group_name) {
212
$mail = new PHPMailer();
214
foreach(self::get_users($group_name) as $member) {
215
if(function_exists('mb_encode_mimeheader')) {
216
$member['fullname'] = mb_encode_mimeheader($member['fullname']);
218
$mail->AddBCC($member['email'], $member['fullname']);
221
return $this->send($mail);
224
} // AmpacheMail class