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