-
Notifications
You must be signed in to change notification settings - Fork 0
/
MassMail.inc.php
79 lines (66 loc) · 1.8 KB
/
MassMail.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/**
* @file classes/mail/MassMail.inc.php
*
* Copyright (c) 2000-2013 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class MassMail
* @ingroup mail
*
* @brief Helper class to send mass emails
*/
import ('classes.mail.MailTemplate');
class MassMail extends MailTemplate {
var $callback;
var $frequency;
/**
* Constructor
*/
function MassMail($emailKey = null, $locale = null, $enableAttachments = null) {
parent::MailTemplate($emailKey, $locale, $enableAttachments);
$this->callback = null;
$this->frequency = 10;
}
/**
* Set the callback function (see PHP's callback pseudotype); this
* function will be called for every n emails sent, according to the
* frequency.
* @param $callback callback
*/
function setCallback(&$callback) {
$this->callback =& $callback;
}
/**
* Set the frequency at which the callback will be called (i.e. each
* n emails).
*/
function setFrequency($frequency) {
$this->frequency = $frequency;
}
/**
* Send the email.
* @return boolean
*/
function send() {
@set_time_limit(0);
$realRecipients = $this->getRecipients();
$realSubject = $this->getSubject();
$realBody = $this->getBody();
$index = 0;
$success = true;
$max = count($realRecipients);
foreach ($realRecipients as $recipient) {
$this->clearAllRecipients();
$this->addRecipient($recipient['email'], $recipient['name']);
$this->setSubject($realSubject);
$this->setBody($realBody);
$success = $success && MailTemplate::send(false);
$index++;
if ($this->callback && ($index % $this->frequency) == 0) call_user_func($this->callback, $index, $max);
}
$this->setRecipients($realRecipients);
return $success;
}
}
?>