xref: /dokuwiki/inc/Subscriptions/SubscriptionSender.php (revision 47de339b47c45069e8b9525bc0ef4396bcc60cfd)
1479c05b1SMichael Große<?php
2479c05b1SMichael Große
3479c05b1SMichael Großenamespace dokuwiki\Subscriptions;
4479c05b1SMichael Große
5479c05b1SMichael Große
6479c05b1SMichael Großeuse Mailer;
7479c05b1SMichael Große
8479c05b1SMichael Großeabstract class SubscriptionSender
9479c05b1SMichael Große{
10*47de339bSMichael Große    private $mailer;
11*47de339bSMichael Große
12*47de339bSMichael Große    public function __construct(Mailer $mailer = null)
13*47de339bSMichael Große    {
14*47de339bSMichael Große        if ($mailer === null) {
15*47de339bSMichael Große            $mailer = new Mailer();
16*47de339bSMichael Große        }
17*47de339bSMichael Große        $this->mailer = $mailer;
18*47de339bSMichael Große    }
19479c05b1SMichael Große
20479c05b1SMichael Große
21479c05b1SMichael Große    /**
22479c05b1SMichael Große     * Helper function for sending a mail
23479c05b1SMichael Große     *
24479c05b1SMichael Große     * @author Adrian Lang <lang@cosmocode.de>
25479c05b1SMichael Große     *
26479c05b1SMichael Große     * @param string $subscriber_mail The target mail address
27479c05b1SMichael Große     * @param string $subject         The lang id of the mail subject (without the
28479c05b1SMichael Große     *                                prefix “mail_”)
29479c05b1SMichael Große     * @param string $context         The context of this mail, eg. page or namespace id
30479c05b1SMichael Große     * @param string $template        The name of the mail template
31479c05b1SMichael Große     * @param array  $trep            Predefined parameters used to parse the
32479c05b1SMichael Große     *                                template (in text format)
33479c05b1SMichael Große     * @param array  $hrep            Predefined parameters used to parse the
34479c05b1SMichael Große     *                                template (in HTML format), null to default to $trep
35479c05b1SMichael Große     * @param array  $headers         Additional mail headers in the form 'name' => 'value'
36479c05b1SMichael Große     * @return bool
37479c05b1SMichael Große     */
38479c05b1SMichael Große    protected function send($subscriber_mail, $subject, $context, $template, $trep, $hrep = null, $headers = array()) {
39479c05b1SMichael Große        global $lang;
40479c05b1SMichael Große        global $conf;
41479c05b1SMichael Große
42479c05b1SMichael Große        $text = rawLocale($template);
43479c05b1SMichael Große        $subject = $lang['mail_'.$subject].' '.$context;
44*47de339bSMichael Große        $mail = $this->mailer;
45479c05b1SMichael Große        $mail->bcc($subscriber_mail);
46479c05b1SMichael Große        $mail->subject($subject);
47479c05b1SMichael Große        $mail->setBody($text, $trep, $hrep);
48479c05b1SMichael Große        if(in_array($template, array('subscr_list', 'subscr_digest'))){
49479c05b1SMichael Große            $mail->from($conf['mailfromnobody']);
50479c05b1SMichael Große        }
51479c05b1SMichael Große        if(isset($trep['SUBSCRIBE'])) {
52479c05b1SMichael Große            $mail->setHeader('List-Unsubscribe', '<'.$trep['SUBSCRIBE'].'>', false);
53479c05b1SMichael Große        }
54479c05b1SMichael Große
55479c05b1SMichael Große        foreach ($headers as $header => $value) {
56479c05b1SMichael Große            $mail->setHeader($header, $value);
57479c05b1SMichael Große        }
58479c05b1SMichael Große
59479c05b1SMichael Große        return $mail->send();
60479c05b1SMichael Große    }
61479c05b1SMichael Große
62479c05b1SMichael Große}
63