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