1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace dokuwiki\Subscriptions; |
4
|
|
|
|
5
|
|
|
use Mailer; |
6
|
|
|
|
7
|
|
|
abstract class SubscriptionSender |
8
|
|
|
{ |
9
|
|
|
private $mailer; |
10
|
|
|
|
11
|
|
|
public function __construct(Mailer $mailer = null) |
12
|
|
|
{ |
13
|
|
|
if ($mailer === null) { |
14
|
|
|
$mailer = new Mailer(); |
15
|
|
|
} |
16
|
|
|
$this->mailer = $mailer; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Helper function for sending a mail |
22
|
|
|
* |
23
|
|
|
* @param string $subscriber_mail The target mail address |
24
|
|
|
* @param string $subject The lang id of the mail subject (without the |
25
|
|
|
* prefix “mail_”) |
26
|
|
|
* @param string $context The context of this mail, eg. page or namespace id |
27
|
|
|
* @param string $template The name of the mail template |
28
|
|
|
* @param array $trep Predefined parameters used to parse the |
29
|
|
|
* template (in text format) |
30
|
|
|
* @param array $hrep Predefined parameters used to parse the |
31
|
|
|
* template (in HTML format), null to default to $trep |
32
|
|
|
* @param array $headers Additional mail headers in the form 'name' => 'value' |
33
|
|
|
* |
34
|
|
|
* @return bool |
35
|
|
|
* @author Adrian Lang <[email protected]> |
36
|
|
|
* |
37
|
|
|
*/ |
38
|
|
|
protected function send($subscriber_mail, $subject, $context, $template, $trep, $hrep = null, $headers = []) |
39
|
|
|
{ |
40
|
|
|
global $lang; |
41
|
|
|
global $conf; |
42
|
|
|
|
43
|
|
|
$text = rawLocale($template); |
44
|
|
|
$subject = $lang['mail_' . $subject] . ' ' . $context; |
45
|
|
|
$mail = $this->mailer; |
46
|
|
|
$mail->bcc($subscriber_mail); |
47
|
|
|
$mail->subject($subject); |
48
|
|
|
$mail->setBody($text, $trep, $hrep); |
49
|
|
|
if (in_array($template, ['subscr_list', 'subscr_digest'])) { |
50
|
|
|
$mail->from($conf['mailfromnobody']); |
51
|
|
|
} |
52
|
|
|
if (isset($trep['SUBSCRIBE'])) { |
53
|
|
|
$mail->setHeader('List-Unsubscribe', '<' . $trep['SUBSCRIBE'] . '>', false); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
foreach ($headers as $header => $value) { |
57
|
|
|
$mail->setHeader($header, $value); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return $mail->send(); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|