21 define(
'MAIL_WRAP', 76);
 
   31       parent::__construct();
 
   32       $this->privateParams = array();
 
   34          $defaultEnvelopeSender = 
Config::getVar(
'email', 
'default_envelope_sender');
 
   35          if (!empty($defaultEnvelopeSender)) $this->
setEnvelopeSender($defaultEnvelopeSender);
 
   44       $this->privateParams[$name] = $value;
 
   61       if (($recipients = $this->
getData(
'recipients')) == 
null) {
 
   62          $recipients = array();
 
   64       array_push($recipients, array(
'name' => $name, 
'email' => $email));
 
   66       $this->
setData(
'recipients', $recipients);
 
   75       $this->
setData(
'envelopeSender', $envelopeSender);
 
   87          return $this->
getData(
'envelopeSender');
 
   97       return $this->
getData(
'content_type');
 
  105       $this->
setData(
'content_type', $contentType);
 
  113       return $this->
getData(
'recipients');
 
  121       $this->
setData(
'recipients', $recipients);
 
  129    function addCc($email, $name = 
'') {
 
  130       if (($ccs = $this->
getData(
'ccs')) == 
null) {
 
  133       array_push($ccs, array(
'name' => $name, 
'email' => $email));
 
  159    function addBcc($email, $name = 
'') {
 
  160       if (($bccs = $this->
getData(
'bccs')) == 
null) {
 
  163       array_push($bccs, array(
'name' => $name, 
'email' => $email));
 
  192       if (empty($recipients)) {
 
  217       if (($headers = $this->
getData(
'headers')) == 
null) {
 
  221       foreach ($headers as $key => $value) {
 
  222          if ($value[
'name'] == $name) {
 
  223             $headers[$key][
'content'] = $content;
 
  229          array_push($headers, array(
'name' => $name,
'content' => $content));
 
  232       $this->
setData(
'headers', $headers);
 
  240       return $this->
getData(
'headers');
 
  248       $this->
setData(
'headers', $headers);
 
  258    function addAttachment($filePath, $fileName = 
'', $contentType = 
'', $contentDisposition = 
'attachment') {
 
  259       if ($attachments =& $this->
getData(
'attachments') == 
null) {
 
  260          $attachments = array();
 
  265       if (empty($fileName)) {
 
  266          $fileName = basename($filePath);
 
  269       if (empty($contentType)) {
 
  271          if (empty($contentType)) $contentType = 
'application/x-unknown-content-type';
 
  274       array_push($attachments, array(
 
  276          'filename' => $fileName,
 
  277          'content-type' => $contentType
 
  280       $this->
setData(
'attachments', $attachments);
 
  288       $attachments =& $this->
getData(
'attachments');
 
  298       return ($attachments != 
null && count($attachments) != 0);
 
  306    function setFrom($email, $name = 
'') {
 
  307       $this->
setData(
'from', array(
'name' => $name, 
'email' => $email));
 
  324       if ($email === 
null) $this->
setData(
'replyTo', 
null);
 
  325       $this->
setData(
'replyTo', array(array(
'name' => $name, 
'email' => $email)));
 
  334       if (($replyTos = $this->
getData(
'replyTo')) == 
null) {
 
  337       array_push($replyTos, array(
'name' => $name, 
'email' => $email));
 
  339       $this->
setData(
'replyTo', $replyTo);
 
  348       return $this->
getData(
'replyTo');
 
  364       $this->
setData(
'subject', $subject);
 
  372       return $this->
getData(
'subject');
 
  401       return (self::encodeDisplayName($from[
'name'], $send) . 
' <'.$from[
'email'].
'>');
 
  410       if ($addresses == 
null) {
 
  416          foreach ($addresses as $address) {
 
  417             if (!empty($addressString)) {
 
  418                $addressString .= 
', ';
 
  421             if (empty($address[
'name']) || !$includeNames) {
 
  422                $addressString .= $address[
'email'];
 
  429          return $addressString;
 
  467       if (is_array($this->privateParams)) {
 
  468          foreach ($this->privateParams as $name => $value) {
 
  469             $mailBody = str_replace($name, $value, $mailBody);
 
  473       $mailer = new \PHPMailer\PHPMailer\PHPMailer();
 
  474       $mailer->IsHTML(
true);
 
  475       $mailer->Encoding = 
'base64';
 
  480             $mailer->SMTPSecure = $s;
 
  481             $mailer->SMTPAuth = 
true;
 
  488             $mailer->SMTPDebug = 3;
 
  489             $mailer->Debugoutput = 
'error_log';
 
  493             $mailer->SMTPOptions = array(
 
  495                   'verify_peer' => 
false,
 
  496                   'verify_peer_name' => 
false,
 
  497                   'allow_self_signed' => 
true 
  503       if (($t = $this->
getContentType()) != 
null) $mailer->ContentType = $t;
 
  504       $mailer->XMailer = 
'Public Knowledge Project Suite v3';
 
  505       $mailer->WordWrap = MAIL_WRAP;
 
  506       foreach ((array) $this->
getHeaders() as $header) {
 
  507          $mailer->AddCustomHeader($header[
'key'], $mailer->SecureHeader($header[
'content']));
 
  510       if (($f = $this->
getFrom()) != 
null) {
 
  514             $alreadyExists = 
false;
 
  516                if ($r[
'email'] === $f[
'email']) {
 
  517                   $alreadyExists = 
true;
 
  520             if (!$alreadyExists) {
 
  521                $mailer->AddReplyTo($f[
'email'], $f[
'name']);
 
  524             $site = $request->getSite();
 
  527             if (
Config::getVar(
'email', 
'dmarc_compliant_from_displayname')) {
 
  528                $patterns = array(
'#%n#', 
'#%s#');
 
  529                $replacements = array($f[
'name'], $site->getLocalizedTitle());
 
  530                $f[
'name'] = preg_replace($patterns, $replacements, 
Config::getVar(
'email', 
'dmarc_compliant_from_displayname'));
 
  537          $mailer->SetFrom($f[
'email'], $f[
'name']);
 
  542          $mailer->AddReplyTo($r[
'email'], $r[
'name']);
 
  545          $mailer->AddAddress($recipientInfo[
'email'], $recipientInfo[
'name']);
 
  547       foreach ((array) $this->
getCcs() as $ccInfo) {
 
  548          $mailer->AddCC($ccInfo[
'email'], $ccInfo[
'name']);
 
  550       foreach ((array) $this->
getBccs() as $bccInfo) {
 
  551          $mailer->AddBCC($bccInfo[
'email'], $bccInfo[
'name']);
 
  554       $mailer->Body = $mailBody;
 
  557       $remoteAddr = $mailer->SecureHeader($request->getRemoteAddr());
 
  558       if ($remoteAddr != 
'') $mailer->AddCustomHeader(
"X-Originating-IP: $remoteAddr");
 
  561          $mailer->AddAttachment(
 
  562             $attachmentInfo[
'path'],
 
  563             $attachmentInfo[
'filename'],
 
  565             $attachmentInfo[
'content-type']
 
  570          $success = $mailer->Send();
 
  572             error_log($mailer->ErrorInfo);
 
  575       } 
catch (phpmailerException $e) {
 
  576          error_log($mailer->ErrorInfo);
 
  589       if (
PKPString::regexp_match(
'!^[-A-Za-z0-9\!#\$%&\'\*\+\/=\?\^_\`\{\|\}~]+$!', $displayName)) 
return $displayName;